Path Tracing
CS 319
Advanced Topics in Computer Graphics
John C. Hart
Ray Tracing
• Whitted, CACM 80
• LDS*E
• Rays cast from eye into scene objects lights
Why? Because most rays cast from
light wouldn’t reach eye
• Shadow rays cast at each intersection
Why? Because most rays wouldn’t
reach the light source
• Workload badly distributed
Why? Because # of rays grows
exponentially, and their result
becomes less influential
Tough Cases
• Caustics
– Light focuses through a specular
surface onto a diffuse surface
– LSDE
– Which direction should secondary
rays be cast to detect caustic?
• Bleeding
– Color of diffuse surface reflected in
another diffuse surface
– LDDE
– Which direction should secondary
rays be cast to detect bleeding?
Path Tracing
• Kajiya, SIGGRAPH 86
• Diffuse reflection spawns infinite rays
• Pick one ray at random objects lights
• Cuts a path through the dense ray tree
• Still cast an extra shadow ray toward
light source at each step in path
• Trace 40 paths per pixel
Approximate
Integration
• Can’t solve integral symbolically
• Replace continuous integral with
discrete summation
f(x)dx Sf(xi)Dxi
• Discretization requires sampling
• Potential Sampling Problems
• Aliasing
– Jitter samples
• Biasing
– Ensure samples properly distributed
• Inaccuracy
– Ensure samples representative
Importance Sampling
• Areas of constant illumination need
few samples
– walls, floors, table tops
• Areas of interesting illumination need
many samples
– edges, shadow boundaries, caustic
boundaries
– cast rays in high variance directions
of reflectivity
• Important that bright areas receive at
least one sample
– cast a ray directly to light source
– cast a ray in highlight direction of
reflectivity
Stratified Sampling
• Add sample until variance falls below
threshold
• Sequential Uniform Sampling
– Lee, Redner and Uselton
SIGGRAPH 85
– Subdivide largest area first
– Breadth first subdivision
• Hierarchical Integration
– Weight samples by area represented
– Variance becomes O(1/n2) instead
of O(1/n)
Examples
Jensen, Stanford
Probability Distributions
p(z) Uniform pdf
from a to b
• Continuous real random variable z 1/(b-a)
• Probability density function (pdf) p(z) 0 z
– Prob. of choosing a (P[z=a]) is p(a) a b
– Prob. of a z b is ab p(z)dz
p(z) = 2z
– Pdf is always positive: p(z) 0 z
– Pdf sums to 100%: p(z)dz = 1 2
• Expected value: E[f(z)] = f(z)p(z)dz 1
– Linear, regardless of corr. of f and g
E[f(z)+g(z)] = E[f(z)] + E[g(z)] 0 z
0 1
• Variance: V[z] = E[(z – E[z])2] Prob. z < 50% is 25%
– Easier to compute as: E[z2] – E[z]2
L(w)
Monte Carlo Integration
• Expected value of f w
Uniform samples waste too
– Given random variable z much time measuring low light
L(w)
– With pdf p
E[f(z)] = f(z)p(z)dz
• Implemented as w
Non-uniform samples skewed
1 N
f (z ) p(z )dz N f (z i )
i 1
toward brighter directions, but
bias result to appear too bright
• So to integrate some function g Dividing by pdf gives
– Pick samples z with pdf p, then
multiple samplesin brighter
areas less weight.
1 N g (z i ) Ideal pdf is a normalized
g (z )dz N p(z i )
i 1
version of the integrand.
Monte Carlo Path Tracing
• Reflectance equation
Lr(wr) = Le(wr) + Wfr(wi,wr)Li(wi) cosqi dwi
• Path tracing
– Repeated recursive evaluation of
f r (wi , wr ) Li (wi ) cos q i Dwi
Lr (wr ) Le (wr )
p(wi )
• Assume diffuse surface fr(wi,wr) = r/p
• Setting p(wi) = (1/p) cos qi yields
Lr(wr) = Le(wr) + rLi(wi) Dwi
• How can we pick wi with prob. (1/p) cos qi ?
– Use Nusselt analog of random disk points
Sampling Strategies
• Sampling incident radiance
L(x, x) f r (x, x, x)G(x, x) L(x, x)dx
– Bias samples toward direction of
maximal incident radiance
• Sampling the BRDF
L(wr ) f r (wi , wr ) L(wi ) cos q i dwi
– Bias samples toward directions of
maximal reflectance