Path tracing
Path tracing is a rendering algorithm in computer graphics that simulates how light interacts with objects, voxels, and participating media to generate realistic images.
This ray tracing technique uses the Monte Carlo method to accurately model global illumination, simulate different surface characteristics, and capture a wide range of effects observable in a camera system, such as optical properties of lenses or the impact of shutter speed. By incorporating physically accurate materials and light transport models, it can produce photorealistic results but requires significant computational power. Performance is often constrained by VRAM/RAM capacity and memory bandwidth, especially in complex scenes, necessitating denoising techniques for practical use. Additionally, the Garbage In, Garbage Out principle applies - inaccurate scene data, poor geometry, low-quality materials, or incorrect rendering settings can negatively impact the final output, regardless of rendering precision.
Due to its accuracy, unbiased nature, and algorithmic simplicity, path tracing is commonly used to generate reference images when testing the quality of other rendering algorithms. Fundamentally, the algorithm works by integrating the light arriving at a point on an object’s surface, where this illuminance is then modified by a surface reflectance function to determine how much light contributes to the final image, as seen by the camera. This integration procedure is repeated for every pixel in the output image, ensuring detailed evaluation of each one. The number of samples per pixel determines the level of detail and quality of the final render, with more samples generally improving image clarity. Rendering performance is often measured in mega samples per second, which reflects how many millions of samples can be processed per second, directly impacting rendering speed. Several variants of path tracing, such as bidirectional path tracing and Metropolis light transport, have been developed to improve efficiency in various types of scenes, reducing noise and speeding up convergence.
History
The rendering equation and its use in computer graphics was presented by James Kajiya in 1986. Path tracing was introduced then as an algorithm to find a numerical solution to the integral of the rendering equation. A decade later, Lafortune suggested many refinements, including bidirectional path tracing.Metropolis light transport, a method of perturbing previously found paths in order to increase performance for difficult scenes, was introduced in 1997 by Eric Veach and Leonidas J. Guibas.
More recently, CPUs and GPUs have become powerful enough to render images more quickly, causing more widespread interest in path tracing algorithms. Tim Purcell first presented a global illumination algorithm running on a GPU in 2002. In February 2009, Austin Robison of Nvidia demonstrated the first commercial implementation of a path tracer running on a GPU, and other implementations have followed, such as that of Vladimir Koylazov in August 2009. This was aided by the maturing of GPGPU programming toolkits such as CUDA and OpenCL and GPU ray tracing SDKs such as OptiX.
Path tracing has played an important role in the film industry. Earlier films had relied on scanline rendering to produce CG visual effects and animation. In 1998, Blue Sky Studios rendered the Academy Award-winning short film Bunny with their proprietary CGI Studio path tracing renderer, featuring soft shadows and indirect illumination effects. Sony Pictures Imageworks' Monster House was, in 2006, the first animated feature film to be rendered entirely in a path tracer, using the commercial Arnold renderer. Also, Walt Disney Animation Studios has been using its own optimized path tracer known as Hyperion ever since the production of Big Hero 6 in 2014. Pixar Animation Studios has also adopted path tracing for its commercial RenderMan renderer.
Description
Kajiya's rendering equation adheres to three particular principles of optics; the Principle of Global Illumination, the Principle of Equivalence, and the Principle of Direction.In the real world, objects and surfaces are visible due to the fact that they are reflecting light. This reflected light then illuminates other objects in turn. From that simple observation, two principles follow.
I. For a given indoor scene, every object in the room must contribute illumination to every other object.
II. Second, there is no distinction to be made between illumination emitted from a light source and illumination reflected from a surface.
Invented in 1984, a rather different method called radiosity was faithful to both principles. However, radiosity relates the total illuminance falling on a surface with a uniform luminance that leaves the surface. This forced all surfaces to be Lambertian, or "perfectly diffuse". While radiosity received a lot of attention at its introduction, perfectly diffuse surfaces do not exist in the real world. The realization that scattering from a surface depends on both incoming and outgoing directions is the key principle behind the bidirectional reflectance distribution function. This direction dependence was a focus of research resulting in the publication of important ideas throughout the 1990s, since accounting for direction always exacted a price of steep increases in calculation times on desktop computers. Principle III follows.
III. The illumination coming from surfaces must scatter in a particular direction that is some function of the incoming direction of the arriving illumination, and the outgoing direction being sampled.
Kajiya's equation is a complete summary of these three principles, and path tracing, which approximates a solution to the equation, remains faithful to them in its implementation. There are other principles of optics which are not the focus of Kajiya's equation, and therefore are often difficult or incorrectly simulated by the algorithm. Path tracing is confounded by optical phenomena not contained in the three principles. For example,
- Bright, sharp caustics; radiance scales by the density of illuminance in space.
- Subsurface scattering; a violation of Principle III above.
- Chromatic aberration, fluorescence, iridescence; light is a spectrum of frequencies.
Algorithm
Color TracePath
void Render
All the samples are then averaged to obtain the output color. Note this method of always sampling a random ray in the normal's hemisphere only works well for perfectly diffuse surfaces. For other materials, one generally has to use importance sampling, i.e. probabilistically select a new ray according to the BRDF's distribution. For instance, a perfectly specular material would not work with the method above, as the probability of the new ray being the correct reflected ray – which is the only ray through which any radiance will be reflected – is zero. In these situations, one must divide the reflectance by the probability density function of the sampling scheme, as per Monte Carlo integration.
There are other considerations to take into account to ensure conservation of energy. In particular, in the naive case, the reflectance of a diffuse BRDF must not exceed or the object will reflect more light than it receives.
Bidirectional path tracing
Sampling the integral can be done by either of the following two distinct approaches:- Backwards path tracing, where paths are generated starting from the camera and bouncing around the scene until they encounter a light source. This is referred to as "backwards" because starting paths from the camera and moving towards the light source is opposite the direction that the light is actually traveling. It still produces the same result because all optical systems are reversible.
- Light tracing, where paths are generated starting from the light sources and bouncing around the scene until they encounter the camera.
Bidirectional path tracing provides an algorithm that combines the two approaches and can produce lower variance than either method alone. For each sample, two paths are traced independently: one from the light source and one from the camera. This produces a set of possible sampling strategies, where every vertex of one path can be connected directly to every vertex of the other. The original light tracing and backwards path tracing algorithms are both special cases of these strategies. For light tracing, it is connecting the vertices of the camera path directly to the first vertex of the light path. For backwards path tracing, it is connecting the vertices of the light path to the first vertex of the camera path. In addition, there are several completely new sampling strategies, where intermediate vertices are connected. Weighting all of these sampling strategies using multiple importance sampling creates a new sampler that can converge faster than unidirectional path tracing, even though more work is required for each sample. This works particularly well for caustics or scenes that are lit primarily through indirect lighting.
Performance
A path tracer continuously samples pixels of an image. The image starts to become recognizable after only a few samples per pixel, perhaps 100. However, for the image to "converge" and reduce noise to acceptable levels usually takes around 5000 samples for most images, and many more for pathological cases. Noise is particularly a problem for animations, giving them a normally unwanted "film grain" quality of random speckling.The central performance bottleneck in path tracing is the complex geometrical calculation of casting a ray. Importance sampling is a technique which is motivated to cast fewer rays through the scene while still converging correctly to outgoing luminance on the surface point. This is done by casting more rays in directions in which the luminance would have been greater anyway. If the density of rays cast in certain directions matches the strength of contributions in those directions, the result is identical, but far fewer rays were actually cast. Importance sampling is used to match ray density to Lambert's cosine law, and also used to match BRDFs.
Metropolis light transport can result in a lower-noise image with fewer samples. This algorithm was created in order to get faster convergence in scenes in which the light must pass through odd corridors or small holes in order to reach the part of the scene that the camera is viewing. It has also shown promise in correctly rendering pathological situations with caustics. Instead of generating random paths, new sampling paths are created as slight mutations of existing ones. In this sense, the algorithm "remembers" the successful paths from light sources to the camera.