Path Tracing - Literature Research Rick de Bruijne May 17, 2011 1
Contents 1 Abstract 3 2 Natural Phenomena 4 2.1 Motion Blur....................................... 4 2.2 Fresnel.......................................... 4 2.3 Participating Media.................................. 5 2.4 Subsurface Scattering................................. 6 2.5 Dispersion........................................ 7 3 Reducing variance 9 3.1 Stratied Sampling................................... 9 3.2 Russian Roulette.................................... 10 3.3 Importance Sampling.................................. 11 3.4 Next Event Estimation................................. 11 3.5 Bi-Directional Path Tracing.............................. 12 2
1 Abstract This report is an ongoing eort to map the most interesting extensions to a basic Kajiya path tracer. Path tracing is in essence a big Monte Carlo estimator, i.e. an estomator which approximates the value of an arbitrary integral. In the case of a path tracer, the integral is the Rendering Equation (eq. 1.1) deviced by Kajiya [6]. The equation describes how the lighting of a point is dependent of the light it emits and how light is reaches it from other light sources, both direct and indirect (by reecting of other surfaces). [ ˆ ] I(x, x ) = g(x, x ) ɛ(x, x ) + ρ(x, x, x )I(x, x )dx (1.1) S where: I(x, x ) accounts for the intensity of light from x to x g(x, x ) is the geometry term, i.e. can x be seen from x ɛ(x, x ) accounts for the intensity of light emitted from x to x ρ(x, x, x ) accounts for the indirect lighting from x to x via x I(x, x ) accounts for the intensity of light from x to x S... dx is the union of all the surfaces (S = S i ) A Monte Carlo path tracer uses a many dimensional integrand. It includes integrating over a pixel (x, y) for anti aliassing, over a lens (u, v) for depth of eld, over time (t) for motion blur and over wavelengths (λ) for dispersion. These dimensions are then raised to the power of the recursion depth to give the nal number of dimensions used: d = (x, y; u, v; t; λ) depth In this report, we give an overview of existing methods to enhance or improve a path tracer. We describe natural phenomena which will increase realism, as well as variance reduction methods which will decrease rendertime. 3
2 Natural Phenomena Kajiya's version of the rendering equation only applies to basic direct/indirect lighting, it does not handle phenomena such as subsurface scattering or uoresence. In this section, we will discuss some of the additional eects which can be handled with path tracing. 2.1 Motion Blur Figure 2.1: Motion blur in a ray tracer Motion blur is caused by extending the rendering equation to also integrate over time. If an acceleration structure is used, it needs to account for the entire integrand over time. A method for doing this is to make a bounding box large enough to contain the object everywhere between t min and t max, or to move it box along with the object. 2.2 Fresnel The Fresnel formula describes the ratio between the amount of light being reected and refracted of a surface; e.a. how much of the incoming light is reected/refracted when it hits a transparant object. n 1 cosθ i n 2 1 R s = n 1 cosθ i n 2 1 + ( n 1 n 2 sinθ i ) 2 ( n 1 n 2 sinθ i ) 2 (2.1) where: R s is the reection coecient n 1 is the refractive index of the medium being left n 2 is the refractive index of the medium entered θ i is the angle of the incident ray The result is dependent on the light's incoming angle in comparison to the surface normal: a greater angle has a bigger reection ratio while a shallower angle has a greater refraction ratio. The Fresnel formula (2.1) knows two major versions: one for conducting and one for dielectric (non-conducting) materials. The formula is very expensive, it contains multiple square roots, 4
Figure 2.2: Sphere rendered without (left) and with (right) the Fresnel eect. multiplications and divisions. Therefore, for eciency, the Schlick approximation is used instead of the Fresnel formula(2.2). where: R(θ) = R 0 + (1 R 0 )(1 cosθ) 5 (2.2) θ is the incedent angle R(θ) is the reection coecient R 0 is the reectance at normal indices, i.e. Fresnel value at θ = 0 The result of Schlick diers only slightly from Fresnel, as can be seen in Figure 2.3. It has less than 1% error [10] compared to the original equation and executes much faster since it has only 2 additions and 4 multiplications. Figure 2.3: Fresnel values for diamant, glass, copper and gold (left); Schlick's appriximation (right). [10] 2.3 Participating Media Participating media causes eects like fog. There are three dierent eects caused by participating media: light absorption, emission and scattering. The simplest participating media only absorb light (e.g. smoke), which means that the light passing through the medium is attenuated based on the density of the medium, as dened by equation 2.3 [8]. The equation states that the intensity of light at distance s (I(s)) is based on the original intensity (I 0 ) and the integrand S over the distance ( ) with regard to the extinction coecient (τ(t)): 0 5
I(s) = I 0 exp ( ˆ S 0 τ(t)dt An example of a participating media that emits light are ames. The amount of light emitted along the length of the ray is dened by equation 2.4, there the intensity is aected by the source term (g(t)), i.e. the light emitted by the media: ) (2.3) ˆ S I(s) = I 0 + g(t)dt (2.4) 0 Because real particles both absorb and emit light, the equations for absorbtion and emission have to be combined. Max [8] derives an equation which gives an inensity at the eye: ( ) ( ) I(D) = I 0 exp ˆ D 0 τ(t)dt + ˆ D 0 g(s) exp ˆ D s τ(t)dt ds (2.5) The rst part represents the light coming from the background, multiplied by the cloud's transparency, the second part is the integrand for the contribution of the medium g(s) at each point s multiplied by the transparency between s and the eye. Real particles don't just emit or absorb light, they also scatter it. This means that at arbitrary points, light is scattered in dierent directions. This means that light can be scattered away from the eye and towards the eye. Figure 2.4: Rising smoke by Henrik Wann Jensen, 2000. 2.4 Subsurface Scattering Many materials have the characteristic that light that enters it at one point may exit at another point quite far away. Subsurface light transport is one of the key mechanisms that gives the characteristic apearances to materials such as marble, skin and candles. 6
Figure 2.5: Scattering of light in a BRDF (left) and a BSSRDF (right). [4] The bidirectional scattering-surface reectance distribution function (BSSRDF [4]) can describe the light transport between two rays that hit a surface, whereas the normal BRDF assumes that light entering a matrial exits at the same position and time (Figure 2.4). The bidirectional distribution function (BRDF, ρ(x, x, x ) in equation 1.1) is an approximation of the BSSRDF, it assumes that light enters and leaves an object at the same point. For a BSSRDF, S(x i, ω i ; x 0, ω 0 ) the outgoing radiance, L i (x i, ω i ) at point x 0 in direction ω i is computed by taking the integrand over the incoming directions ( ) and area ) with regard to surface normal n: 2π ( A L o (x o, ˆ ˆ ω o ) = S(x i, ω i ; x 0, ω o )L i (x i, ω i )( n ω i )dω i A(x i ) A 2π As light travels a greater distance through the medium, the value of S generally deminishes. The light transport beneath a surface is described by the same principles as light transport within participating media. Figure 2.6: Marble bust rendered without (left) and with (right) subsurface scattering. [4] 2.5 Dispersion Dispersion is the natural eect of the occurrence of rainbows eects when light is fragmented through an object. This happens when light which consists of a variety of dierent wavelengths is split into its spectral components when it hits the boundary of a refractive material. The resulting color is calculated by taking the integrand over the dierent wavelengths. The split is non-linearly dependent on the wavelengths. The amount of splitting is related to a set of material constants which can only be found by being measured in experiments. For the 7
Figure 2.7: Incident ray being split by a prism into separate wavelengths. [13] implementation in a Monte Carlo renderer, the default RGB color space isn't sucient. A better method is needed which uses a device independent color space (e.g. CIE CYZ). This color space can be used in internal calculations and has to be transformed into RGB for displaying the nal result. Figure 2.8: A lead crystal paperweight rendered without dispersion ( left) and with dispersion (right). [13] 8
3 Reducing variance A Monte Carlo renderer uses random variables, which represent a distribution of variables. The distribution can be expressed as a function relating possible values to probabilities. A continious function, as used in Monte Carlo, is called a probability density function (pdf). By denition a pdf, p, must comply to two requirements (where x R) [1]: x : p(x) 0 Ω p(x)dx = 1 The variance of the Monte Carlo estimator of integral f with pdf q can be dened by ( N ) f(x i ) V = 1 ( ) f(ω) q(x i ) N V q(ω) i=1 (3.1) This implies that the variance will ( go ) to zero as N. The expression also implies that the variance will only decrease by O N 1 2, so 4 times as many samples need to be taken to halve the variance. In the following section we will discuss a few techniques to reduce variance. 3.1 Stratied Sampling Random sampling (also called stochastic sampling) suers from a great variance. There is no guarantee that the distribution is uniform; the sample points can clump together and leave gaps (see Figure 3.1). Stratied sampling subdivides the original space into a group of nonoverlapping regions. When taking a single sample from each region, a better distribution is guaranteed, reducing variance. Each region is known as a stratum, multiple stratum are called strata. Figure 3.1: 16 random samples (left); 256 random samples (right). A simple method for stratied sampling is jittered sampling. The sampling region is subdivided into a uniform grid and a random sample is taken in each stratum. This method yields a better distribution than random sampling, where all samples could end up in one stratum. 9
Figure 3.2: 16 jittered samples (left); 256 jittered samples (right). Another method is Poisson-disk sampling, which is a method of random sampling with the restriction that the minimum distance between the points is at least ε. If no point can be added without breaking the poison-disk property, the pattern is maximal. When the distribution is maximal, a relaxation method like Lloyd's relaxation can be used to add more points: the generated points are moved to their Voronoi region's centroids, creating room for more samples. [5] Figure 3.3: 16 Poisson-disk sampled (left); 256 Poisson Disk sampled (right). 3.2 Russian Roulette Russian Roulette addresses the problem of ray which contribute little to the nal image. A termination probability is used to terminate a ray when its contribution becomes too little. A compensation will have to be made for the rays that are terminated; the rays that continue 1 will be scaled by their probability of evaluation ( p evaluate ). Russian roulette will never reduce variance, but will actually increase it. However, because it terminates rays early, it increases the overall eciency. Another eect of using russian roulette is that the renderer allows for paths of arbitrary length, even allowing for inntely long paths, removing bias caused by having a xth-length path. 10
Imagine we want to nd an average of the function f(x)by taking N = 100 evaluations (eq 3.2). v = 1 N N f(x i ) (3.2) i=0 If the probability of evaluation is 0.5, we need to scale by 1 0.5 = 2.0 in the event that the evaluation is chosen.if f(x) is a constant function that returns 1, the full sum would give 100 100 = 1. The Russian Roulette version would not give the exact answer, but would converge to it. The full sum would be close to 50 because the function is evaluated only half the time. However, because we scaled by 2, the result would roughly be 100, which would give the nal result of roughly 1. This works with every probability of p = (0, 1] 1. 3.3 Importance Sampling Importance sampling exploits that the Monte Carlo estimator converges more quickly when samples are taken from a distribution which is proportional to the function in the integrand used. Equation 3.1 tells us that the variance is dependent on f(ω) q(ω). If the variance of this ratio can be decreased, the over variance can be reduced without increasing the number of samples. Importance sampling is the technique of choosing a sampling distribution ( q) to minimize variance of the ratio. Not all importance sampling will decrease variance, a poorly chosen q will actually increase variance. The two cases which can increase variance are a very small q where f is relatively large ( f q will be very large), or a large q where f is relatively small ( f q will be very small). The rst case is generally more problematic than the second. In the rst case, the ratio can appcoach innity, while in the second case it cannot get smaller than 0. By reducing the probability of a very small q where f is very large, the robustnes of the Monte Carlo estimator is increased. This can be done by replacing q with a mixture distribution that includes a uniform density, u(ω) over the domain q (ω) = αq(ω) + (1 α)u(ω) This quarantees that the new distribution (q ) will never be smaller than (1 α)u(ω). This places an upper bound on the variance of the estimator. 3.4 Next Event Estimation When a path doesn't hit a light source, its radiance is 0. Since it is unlikely for a ray to hit a light by sampling random directions, many rays will return a black pixels. We can sample light sources directly, splitting direct and indirect illumination (creating two separate Monte Carlo processes). Direct illumination for a single light is based on picking a random point on the light and casting a shadow ray. If the light is hit, its radiance is contributed to the nal result. The contribution is based on the angle of the shadow ray to the surface normal of the shaded object and the distance between the object and the light source. The direct ligting integrator can be dened as ([9], equation 15.1): ˆ L o (p, ω o ) = L e (p, ω o ) + f(p, ω o, ω i )L d (p, ω i ) cosθ i dω i S 2 1 There is no Russian Roulette for p=1. 11
where: Lo (p, ω o ) existant radiance from a point p on a surface in direction ω o L e (p, ω o ) emitted radiance from the surface at point p f(p, ω o, ω i ) incoming radiance over the sphere L d (p, ω i ) incident radiance from light sources cosθ i angle between incident ray and the surface normal S 2 the sphere of incident directions around p When multiple light sources exists, the probability of sampling each is based on their surface area. All probabilities are scaled so that the sum will be 1: N p i = A i j=0 First, a light source to sample is chosen by taking a sample in the range (0, 1), after which a random point is sampled on the chosen light source. The nal result is found by adding the direct lighting to the radiance determined by basic Monte Carlo path tracing. When a light source is hit with a random diuse bounce, it is not counted; the lighting is already handled with the next event estimation. A j 1. Figure 3.4: Cornell box rendered with (left) and without (right) next event estimation. Both pictures are rendered with 4 samples. 3.5 Bi-Directional Path Tracing In bi-directional path tracing, rays are traced both in the forward direction (from a lightsource) and in the reverse direction (from the eye). Rays in the forward direction are traced untill they are terminated by russion roulette or when they have reached a max depth. Rays in the reverse direction are traced in the same manner, but are also terminated when they strike a light source. All hit points on the respective paths are then connected using shadow rays and the approximate contributions are added to the pixel being rendered (Figure 3.5). We will have to assign a weight of the path relative to the probability of having the path in the sampling scheme. At each point on the eye path the estimates for the indirect lighting via the rest of the path and via the light path are weighted. For specular surfaces, the estimate found by following the eye path is mostly relied upon. For diuse surfaces, the estimate fround through the contributions of the light path are more likely to be important. Therefore, the weight is 12
Figure 3.5: A scematic representation of the bi-directional path tracing algorithm [7]. chosen proportional to a measure of the degree of specularity at the surface at the point being evaluated along the eye path. 13
References [1] K. Bala, P. D. (editors, J. F. Talbot, D. Cline, and P. Egbert. Importance resampling for global illumination. [2] S. S. Csi, L. Szirmay-kalos, and C. Kelemen. Variance reduction for russian-roulette. A. Slack, Solid State Physics, 34:2003, 2003. [3] G. W. Imbens and T. Lancaster. Ecient estimation and stratied sampling. Journal of Econometrics, 74(2):289318, October 1996. [4] H. W. Jensen, S. R. Marschner, M. Levoy, and P. Hanrahan. A practical model for subsurface light transport. In Proceedings of the 28th annual conference on Computer graphics and interactive techniques, SIGGRAPH '01, pages 511518, New York, NY, USA, 2001. ACM. [5] T. R. Jones. Ecient generation of poisson-disk sampling patterns. journal of graphics, gpu, and game tools, 11(2):2736, 2006. [6] J. T. Kajiya. The rendering equation. SIGGRAPH Comput. Graph., 20:143150, August 1986. [7] E. P. Lafortune and Y. D. Willems. Bi-directional path tracing. In Proceedings of Third International Conference on Computational Graphics and Visualization Techniques (COM- PUGRAPHICS 1993), pages 145153, 1993. [8] N. Max. Optical models for direct volume rendering. IEEE Transactions on Visualization and Computer Graphics, 1:99108, June 1995. [9] M. Pharr and G. Humphreys. Physically Based Rendering, Second Edition: From Theory To Implementation. Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 2nd edition, 2010. [10] C. Schlick. An inexpensive brdf model for physically-based rendering. Computer Graphics Forum, 13:233246, 1994. [11] P. Shirley and R. K. Morley. Realistic Ray Tracing. A. K. Peters, Ltd., Natick, MA, USA, 2 edition, 2003. [12] P. Shirley, C. Wang, and K. Zimmerman. Monte carlo techniques for direct lighting calculations. ACM Trans. Graph., 15:136, January 1996. [13] E. Wilkie, R. F. Tobler, and W. Purgathofer. Raytracing of dispersion eects in transparent materials. In In WSCG 2000 Conference Proceedings, pages 2000, 2000. 14