CMSC427

Matthias Zwicker Fall 2019

1 Rendering so far Cannot simulate: 1. Reflection, refraction 2. Multiple bounces 3. Area lights 4. Scattering in volumes 5. Wave effects 6. Transient (time dependent) light transport

2 Today A glimpse at realistic light transport simulation • Address points 1-4 on previous slide • Rendering equation • Monte Carlo integration • Solving rendering equation using Monte Carlo

3 Goal: compute radiance field

• Radiance field Lo(x,ωo)

o

4 So far: reflection equation 2 • Given incident light (radiance) Li for all directions ωi over hemisphere H (n), and BRDF f at point x, what is reflected light Lo in direction ωo?

• Li, Lo are radiance distributions: defined for each point x and direction ωi, ωo

Reflected radiance

Incident radiance

BRDF

(note: we computed a discrete version of this by summing over set of light sources) 5 Problem • Reflection equation assumes incident light

Li is known at any point x, direction ωi • But incident light depends on reflected

light Lo somewhere else in the scene

x‘=r(x,ωi) is point where ray x,ωi hits surface; x‘ related to x via

6 Indirect illumination

• Find incident light Li(x,ωi) by computing reflected Lo(x’,-ωi) at corresponding location x’

• Etc. recursively • Notation tedious, let’s simplify

7 Notation trick • Radiance doesn‘t change along ray (in vacuum)

• Get rid of distinction between incident Li and reflected radiance Lo • Will denote reflected radiance with L

x‘=r(x,ωi) is point where ray x,ωi hits surface; x‘ related to x via ray tracing

8 Rendering equation http://en.wikipedia.org/wiki/Rendering_equation

x‘=r(x,ωi) is point where ray x,ωi hits next surface

Conservation of energy: outgoing light L is sum of

emitted light Le and reflected light, which is integral of incident light weighted by BRDF and cosine term; at each point x and in each

dirction ωo

9 Solution via series expansion • Operator notation

L = E +T{L}

• Series expansion http://en.wikipedia.org/wiki/Liouville-Neumann_series – Start with L=0 on right hand side, substitute resulting left hand side recursively into right hand side L = E + T{E} + T{T{E}} + T{T{T{E}}}… • Infinite sum converges to solution of rendering equation – Intuition: T applied n times to E represents all light that bounced n times; infinite sum adds up over all number of bounces from n=0 to infinity – Convergence because each bounce absorbs some energy; terms get smaller by some factor <1 with each additional bounce

10 Numerical solution • How to compute the terms T{E}, T{T{E}}, T{T{T{E}}} etc. of the infinite sum? – Each term is complicated, high-dimensional integral (integrating over all light paths of a certain length, i.e., number of bounces) • Solution: Monte Carlo integration

11 2 Monte Carlo integration http://en.wikipedia.org/wiki/Monte_Carlo_integration • 1D example: want to compute numerically

• Given uniform random variables

• Monte Carlo estimator for the integral with N random samples 3 Expected value http://en.wikipedia.org/wiki/Monte_Carlo_integration 4 Variance http://en.wikipedia.org/wiki/Monte_Carlo_integration 5 Standard deviation Standard deviation (expected error) σ of the estimator

• The expected error converges with • To get half the error, we need four times the number of samples • Slow convergence … 6 Importance sampling • With general probability density p

known as “importance sampling” • Show as before • Can reduce variance compared to uniform sampling Monte Carlo path tracing https://en.wikipedia.org/wiki/Path_tracing • Evaluate terms E, T{E}, T{T{E}}, T{T{T{E}}} using Monte Carlo integration • For example, one bounce

– j-th sample uses random direction ωi,j – Uniform sample density over hemisphere is p(ω)=1/(2pi)

– Angle between normal and ωi,j is θi,j – Point hit by ray from x in direction ωi,j is x’

17 Monte Carlo path tracing https://en.wikipedia.org/wiki/Path_tracing • For each sample – Trace random path with given maximum length – Evaluate contribution to each term T{E}, T{T{E}}, T{T{T{E}}} for each new path segment, add them up • Pixel color is average over N samples • Tracing paths of certain length implemented as loop or recursion by tracing one ray segment after an other

18 Monte Carlo path tracing https://en.wikipedia.org/wiki/Path_tracing Returns one sample of E + T{E} + T{T{E}} + …+ Tmaxdepth{E}

Check if maximum path length is reached

Diffuse BRDF

Recursive ray tracing

19 Monte Carlo path tracing • Each call to TracePath returns one sample of E + T{E} + T{T{E}} + …+ Tmaxdepth{E} • Color of each pixel is average over N samples – N calls to TracePath with initial ray starting at eye, going through pixel

20 Extensions to basic path tracing (material profided for interested readers, not considered part of course material) Advanced light transport effects • Reflection and refraction Advanced algorithms • Russian roulette • Bidirectional path tracing • mapping

… and much more (see further reading http://pbrt.org/)

21 Reflection and refraction

https://en.wikipedia.org/wiki/Rendering_(computer_graphics)

22 Specular reflection & refraction • Perfectly flat, homogeneous materials – Mirror like reflection • Distinguish between dielectrics and conductors • Dielectrics (insulators) – Glass, plastic – Refraction: light enters material and is transmitted in it • Conductors – Metals – No light is transmitted in material • Snell‘s law determines angle of refraction • Fresnel equations determine amount of reflected and refracted light

23 Specular refraction • Light travels at different speeds in different media • Light is bent when it goes from one medium to another • Dielectric materials – Diamond, glass, water, air

24 Index of refraction • Speed of light depends on medium – Speed of light in vacuum – Speed of light in medium • Index of refraction – Air 1.00029 – Water 1.33 – Acrylic glass 1.49

25 Explanations • Fermat’s principle “The actual path between two points taken by a beam of light is the one which is traversed in the least time.“ http://en.wikipedia.org/wiki/Specular_reflection

• “Change in phase velocity leads to bending of light rays” http://en.wikipedia.org/wiki/Snell%27s_law air water

26 Snell’s law http://en.wikipedia.org/wiki/Snell%27s_law • Ratio of sines of angles of incidence and refraction is equal to opposite ratio of indices of refraction

• Vector form to obtain refracted direction r

– Incoming direction v, outgoing refracted direction r – Normal vector n 27 Fresnel equations http://en.wikipedia.org/wiki/Fresnel_equations • Fresnel equations describe fraction of intensity of light that is reflected and refracted • Derived by solving the Maxwell equations – Takes into account of light • Different versions for dielectrics and conductors • Full equations for dielectrics see http://en.wikipedia.org/wiki/Fresnel_equations

28 Path tracing refractive materials • Instead of randomly sampling direction, compute mirror reflection and refraction direction • Randomly pick one of them • Divide contribution by probability of choosing direction

Randomly pick mirror reflection or refraction direction

Fresnel term

29 Limitations • Caustics

https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing

30 Russian roulette • Avoid fixed maximum path length • In each step, stop with certain probability • If did not stop, weight contribution with 1/(probability to continue)

31 Extensions and improvements • Bidirectional path tracing: trace two path segments, one from eye, one from light, connect

Path tracing Bidirectional path tracing 1024 samples per pixel (spp) 1024 samples per pixel (spp)

http://www.jun.ninja/projects/tracy/

32 Extensions and improvements • : two pass technique 1. Trace set of paths from light, store hit points as “” 2. Trace path from eye, look up stored photons (“photon map”)at hit point

Path tracing Photon mapping 1024 samples per pixel (spp) Equal render time

http://www.jun.ninja/projects/tracy/ 33 Extensions and improvements • Light transport in volumetric media – Clouds, fire, smoke, skin, etc.

https://forum.unity.com/threads/experimentation-realistic-human-skin-rendering-with-screen-space-subsurface-scattering.442836/ 34 Further reading

• PBRT, http://pbrt.org/

35