The Rendering Equation and Path Tracing Louis Feng April 22, 2004 April 21, 2004 Realistic Image Synthesis (Spring 2004) 1
Topics The rendering equation Original form Meaning of the terms Integration Path tracing Classical ray tracing Path tracing Bidirectional path tracing April 21, 2004 Realistic Image Synthesis (Spring 2004) 2
The Rendering Equation The rendering equation is a unified description of the rendering problem Previous rendering algorithms (such as radiosity) are approximations to the rendering equation In its original form, the rendering equation is Ixx (, ') = gxx (, ') ε(, xx') ρ(, xx', x")( Ix', x") dx" + S S = S i Ixx (, ') is related to the intensity of light passing from point x' to x gxx (, ') is a "geometry" term ε( xx, ') is related to the intensity of emitted light from point x' to x ρ( xx, ', x") is related to by a patch of surface at x ' the intensity of light scattered from x" to April 21, 2004 Realistic Image Synthesis (Spring 2004) 3 x
More Details About the Integral The outgoing radiance at any surface location in a model is L L e r L (, x ω) = L (, x ω) + L (, x ω) o e r is the emitted radiance is the reflected radiance The total reflected radiance is Lr(, x ω) = fr(, x ω', ω) Li(, x ω')( ω' nd ) ω' f r L i is the BRDF Ω is the incident radiance April 21, 2004 Realistic Image Synthesis (Spring 2004) 4
More Details About the Integral Combine previous equations we get Lo(, x ω) = Le(, x ω) + fr(, x ω', ω) Li(, x ω')( ω' nd ) ω' For computation, we convert from integrating over the hemisphere to integrating the surface locations Recall the differential solid angle is dω '( x) Ω ds ' ( ω ' n') da' = = 2 2 r x' x da' is the projected area April 21, 2004 Realistic Image Synthesis (Spring 2004) 5
More Details About the Integral Introduce a geometry term G Gxx (, ') = ( ω' n')( ω' n) x' x We can rewrite previous radiance integral as L (, x ω) = L (, x ω) + f (, x x' x, ω) L ( x' xv ) (, x x') G(, x x') da' o e r i S S is the set of all surface points Use notation L ( x' x) to denote the radiance leaving x' in the direction towards x i 1 if x and x' are mutually visible V is the visibility function, V = 0 otherwise 2 April 21, 2004 Realistic Image Synthesis (Spring 2004) 6
More Details About the Integral With the new notation, we have L ( x' x) = L ( x' x) + o e S f ( x" x' x) L ( x" x') V( x', x") G( x', x") da" r i This integral differs from the original rendering equation in the geometry term, which encodes the occlusion of surface points by other surface points The term is missing for the emitted radiance from position x. In this case, we consider position x is always visible to the observer When the definition is recursive, is this true in general? April 21, 2004 Realistic Image Synthesis (Spring 2004) 7
More Details About the Integral This integral is recursive, we can use Neumann series expansion to evaluate the equation L = gl + gml m = 0 (1 gm ) I = K( x" x' x) = fr ( x" x' xv ) ( x", x') G( x", x') April 21, 2004 Realistic Image Synthesis (Spring 2004) 8 1 L = (1 gm) gl if M < 1 2 3 e e ( ) e ( ) e S S S m = 0 e gmg ( ) Kx (, x, x ) Kx (, x, x ) k k 1 k 2 1 0 1 L ( x x ) dada da e k k 1 k k 1 0 m gl L = gl + gmgl + g Mg L + g Mg L + = = L e e e
Classical Ray Tracing Light can be traced backwards from observer to the light sources At each intersection point the direct illumination is computed The visibility of the light source is evaluated using shadow rays (dotted lines) If the surface is specular then a specular ray is traced in the reflected or transmitted direction rx (, ω) = x+ d ω April 21, 2004 Realistic Image Synthesis (Spring 2004) 9
Classical Ray Tracing At intersection point x, we find the outgoing radiance in the direction of the ray (, ) (,, ') ω ' n 2 (, ) Φl Lr x ω = fr x ω ω V x p p x 4 π fr is the BRDF n is surface normal p is the position of the light Φl is the power of the light ω ' = ( p x)/ p x, the unit vector in the direction of the light source 0 if x is in shadow V is the visibility function, V = 1 otherwise April 21, 2004 Realistic Image Synthesis (Spring 2004) 10
Classical Ray Tracing Algorithm render image using ray tracing for each pixel pick a ray from the eye through this pixel pixel color = trace(ray) trace(ray) find nearest intersection with scene compute intersection point and normal color = shade(point, normal) return color shade(point, normal) color = 0 for each light source trace shadow ray to light source if shadow ray intersect light source color = color + direct illumination if specular color = color + trace(reflected / refracted ray) return color [Realistic Image Synthesis Using Photon Mapping] April 21, 2004 Realistic Image Synthesis (Spring 2004) 11
Deficiencies Not a full global illumination algorithm Can not compute indirect illumination on diffuse surfaces LD?S*E Basic algorithm can not compute soft chadows, depth of field, and motion blur Need Monte Carlo sampling for these effects April 21, 2004 Realistic Image Synthesis (Spring 2004) 12
A Ray Tracing Example http://graphics.ucsd.edu/~henrik/images/ April 21, 2004 Realistic Image Synthesis (Spring 2004) 13
Path Tracing An extension to classic ray tracing Possible to compute a complete global illumination solution Simulate all possible light bounces in a model L(S D)*E Distributed ray tracing Use stochastic sampling to compute effects such as soft shadows, motion blur, and depth of field Path tracing extends distributed ray tracing by stochastically sampling all possible light paths April 21, 2004 Realistic Image Synthesis (Spring 2004) 14
Path Tracing Mathematically, it s a continuous Markov chain random walk technique for solving the rendering equation Only use one reflected ray to estimate the indirect illumination If use several rays per scattering event, it results in an exponential growth in the number of rays To compute an accurate estimate, use several (a number of) primary rays and average the result April 21, 2004 Realistic Image Synthesis (Spring 2004) 15
Variance in Path Tracing Recall that a property of Monte Carlo integration is the standard error is proportional to 1/ N for N samples Variance in the estimates shows up as noise in the image 1000-10000 path per pixel is typical for noise free images The result is mostly depending on the complexity of the scene Slow varying indirect illumination need lower number of samples We will learn more about Sampling Theory in next lecture April 21, 2004 Realistic Image Synthesis (Spring 2004) 16
Path Tracing Algorithm render image using path tracing for each pixel color = 0 for each sample pick ray from observer through random position in pixel pick a random time and lens position for the ray color = color + trace(ray) pixel color = color / # of samples trace(ray) find nearest intersection with scene compute intersection point and normal color = shade(point, normal) return color shade(point, normal) color = 0 for each light source test visibility of random position on light source if visible color = color + direct illumination color = color + trace(a random reflected ray) return color [Realistic Image Synthesis Using Photon Mapping] April 21, 2004 Realistic Image Synthesis (Spring 2004) 17
Path Tracing Examples This image shows the noisy result after combining only 16 samples for each pixel. It also demonstrates the support of spherical light sources, diffuse inter reflections and soft shadows. [http://www.cs.princeton.edu/~jlawrenc/] April 21, 2004 Realistic Image Synthesis (Spring 2004) 18
Path Tracing Examples April 21, 2004 Realistic Image Synthesis (Spring 2004) [http://www.cs.princeton.edu/~jlawrenc/] 19
Bidirectional Path Tracing An extension to the path tracing algorithm, which traces paths starting from both the eye as well as the light sources Certain paths are easier to sample from the lights Caustics (LS+DE) In situations where the event has small probability but significant contribution, traditional path tracing will produce more noise It is easier to start from the light and trace the ray through specular to diffuse surface, then project to the image plane. April 21, 2004 Realistic Image Synthesis (Spring 2004) 20
Bidirectional Path Tracing Trace two paths: from the eye, path x, and from the light, path y Combine the results by connecting all vertices, including the end points (light and eye) For each vertex-vertex pair, the visibility function V is evaluated with a shadow ray, and compute the individual contribution from the light path vertices to the eye path Light propagates flux, we can t just add the radiance at the vertices ( yj xi) nx L, ( 1) ( 1) (, ) i i j xi xi = fr yj xi xi V xi yj I( y ) 2 j xi x y The radiant intensity for a vertex on the light path is Iy ( x) = Φ ( y) ( y x) n f( y y x) Φ j i i j j i y r j 1 j i ( y ) is the flux of the incoming photon at y from y i j j j 1 April 21, 2004 Realistic Image Synthesis (Spring 2004) 21 j i j
Bidirectional Path Tracing The weighted sum of the contributions from all paths is N p i, j i, j i= 0 j= 0 ij, j i= 0 N i must be normalized in, i N L = w L w w j = 1 for N = 0,1, 2, 3, April 21, 2004 Realistic Image Synthesis (Spring 2004) 22
Bidirectional Path Tracing One choice of weights is use power heuristic w ij, i+ j k = 0 β ij, p =, where β = 2 p β ki, + j k p is the probability density for generating the path x,, x, y, y ( x x ) n ( x x ) n i+ 1 px ( x )= p ( x x ) ij, 0 i j 0 i i+ 1 xi i i+ 1 x i i+ 1 fr i i+ 1 2 xi xi+ 1 p ( x x ) is the probability f i i+ 1 r density for sampling the direciton xi x i + 1 with respect to the projected solid angle April 21, 2004 Realistic Image Synthesis (Spring 2004) 23
Bidirectional Path Tracing Algorithm render image using bidirectional path tracing for each pixel for each sample pos = random position in pixel trace paths(pos) trace path( pixel pos) trace primary ray from observer through pixel pos generate an eye path of scattering events from the primary ray emit random photon from the light source generate a light path of scattering events from the photon combine(eye path, light path) combine(eye path, light path) for each vertex y j on the light path for each vertex x i on the eye path if Vx ( i, y j) == 1 compute weight for the xi yj path add weighted contribution to the corresponding pixel [Realistic Image Synthesis Using Photon Mapping] April 21, 2004 Realistic Image Synthesis (Spring 2004) 24
Bidirectional Path Tracing Properties Bidirectional path tracing uses few samples per pixel than path tracing, but path tracing may still be faster because bidirectional path tracing combines two paths Still has noise Better than path tracing when rendering caustics, except when the caustic is reflected by mirror, where bidirectional path tracing is not better April 21, 2004 Realistic Image Synthesis (Spring 2004) 25
References Books Principles of Digital Image Synthesis, Andrew Glassner Realistic Image Synthesis Using Photon Mapping, Henrik Wann Jensen An Introduction to Ray Tracing, Andrew Gassner Papers Kajiya, J. T., "The rendering equation", Proceedings of the 13th annual conference on Computer graphics and interactive techniques 1986, pp. 143-150. April 21, 2004 Realistic Image Synthesis (Spring 2004) 26