140 likes | 354 Vues
Path Tracing. CS 319 Advanced Topics in Computer Graphics John C. Hart. objects. lights. Ray Tracing. Whitted, CACM 80 LDS*E Rays cast from eye into scene Why? Because most rays cast from light wouldn’t reach eye Shadow rays cast at each intersection
E N D
Path Tracing CS 319 Advanced Topics in Computer Graphics John C. Hart
objects lights Ray Tracing • Whitted, CACM 80 • LDS*E • Rays cast from eye into scene 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?
objects lights Path Tracing • Kajiya, SIGGRAPH 86 • Diffuse reflection spawns infinite rays • Pick one ray at random • 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 S f(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 pdffrom a to b 1/(b-a) • Continuous real random variable z • Probability density function (pdf) p(z) • Prob. of choosing a (P[z=a]) is p(a) • Prob. of azb is abp(z)dz • Pdf is always positive: p(z) 0 z • Pdf sums to 100%: p(z)dz = 1 • Expected value: E[f(z)] = f(z)p(z)dz • Linear, regardless of corr. of f and g E[f(z)+g(z)] = E[f(z)] + E[g(z)] • Variance: V[z] = E[(z – E[z])2] • Easier to compute as: E[z 2] – E[z]2 z 0 a b p(z) = 2z 2 1 z 0 0 1 Prob. z < 50% is 25%
Monte Carlo Integration L(w) w • Expected value of f • Given random variable z • With pdf p E[f(z)] = f(z)p(z)dz • Implemented as • So to integrate some function g • Pick samples z with pdf p, then Uniform samples waste toomuch time measuring low light L(w) w Non-uniform samples skewedtoward brighter directions, butbias result to appear too bright Dividing by pdf gives multiple samplesin brighter areas less weight. Ideal pdf is a normalized version of the integrand.
Monte Carlo Path Tracing • Reflectance equation Lr(wr) = Le(wr) + W fr(wi,wr)Li(wi) cosqi dwi • Path tracing • Repeated recursive evaluation of • Assume diffuse surface fr(wi,wr) = r/p • Setting p(wi) = (1/p) cos qi yields Lr(wr) = Le(wr) + r Li(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 • Bias samples toward direction of maximal incident radiance • Sampling the BRDF • Bias samples toward directions of maximal reflectance