Tachyonic: Photon Mapping

Introduction


Photon Mapping is an extension to ray tracing that enables flexible and efficient global illumination calculations. In particular, photon mapping is very good at handling caustics. It can also be used with Irradiance Caching to efficiently compute soft indirect illumination.


I worked on this project as a CS490 (Supervised Independent Research) project with Dr. Kavita Bala. The project will also be presented in Boom 2003.


Tachyonic Implementation


My implementation of Photon Mapping follows closely the algorithm described in Henrik Jensen's book Realistic Image Synthesis with Photon Mapping. In addition, final gathering and irradiance caching as described in Per Christiensen's paper "Faster Photon Map Global Illumination" is implemented. Please refer to the sites linked for more information on Photon Mapping.


There are various extensions and optimizations that I have implemented. To mention a few, I do not use a projection map to concentrate photons toward specular objects. Instead, I use a rejection test to fill the casutic photon map. Once all the global photons are casted (at this point, the global photon map and the caustic photon map will both have photons), I lock the global photon map. Then, I cast photons into the scene until the caustics photon map is filled. Here, I precompute the initial flux that each caustic photon must carry.


There are also bugs and visual artifacts created by my implementation. Two noticable bugs are the "banding" effects seen in the corner of the boxes. This is a bug in my secondary final gathering implementation. Also, there is an awkward "caustic-like" effect on the red side of the CornellBox image (third image in the "Rendered Image" section below). The errors are strictly mine, and specific to my implementation.


The entire code is written in C++ using only the STL. Some code and ideas were taken from the CS517 base raytracer. Finally, the random number generator was based on M. Matsumoto and T. Nishimura's article. (Please refer to http://www.agner.org/random/.)


The renderer takes a proprietary scene format as input. There are plans to implement converters so that scenes created popular modelers can be imported.


What is a caustic?


A caustic is light focused on a surface. Perhaps a more familiar example of caustics is the varying light patterns formed on a shallow sea floor. Caustics are not the dominant effects of a scene, but are very noticeable when present. Take a wine glass filled with cognac for instance; the absence of caustics would definitely be noticed. It is reasonable to expect some caustics to be formed when there is a specular object present.

 

Caustics formed by a Wine Glass


Caustics are easily formed under curved glass material. When present, caustics contribute greatly to the "realism" of the scene. Most global illumination algorithms cannot render caustics efficiently. Photon Mapping, however, can handle caustics very effectively.


Image rendered by Henrik Jensen.

With Whitted(regular) Ray tracing, rays carry radiance. Because of the reciprocity property of BRDFs, rays can start from the eye and traced back to the light source to return color information. This turns out to be a very good model for rendering objects in the scene. However, because caustics are concentrated light, it is very difficult to capture its effect by tracing rays back toward the light source.


With Photon Mapping, in addition to rays (which carry radiance), photons (which carry flux) are also traced. While rays start out from the eye, photons start out from the light source and bounce around the scene until they are absorbed in a diffuse surface. Because caustics are important in the scene, many photons can be shot toward specular objects. Any photons that follow an (LS+D) path are stored in the caustics photon map.

 

An LS+D path


When photons are traced, any photon that follows an LS+D path are recorded as caustics photons and are stored in the caustics photon map. Any other photons (L(S|D)*D - LS+D) are stored in the global photon map.


Global photons are shot randomly from the light source. However, Caustics photons are concentrated toward specular surfaces, forcing LS+D paths.

 

The stength of Photon Mapping


Here's an illustration of more "interesting" LS+D paths. Notice that photons shot from the light source bounce off of the mirror ball and focus through the glass ball. It is easy to see the photons refracting through the glass (eta = 1.7) orb.


How Photon Mapping Works: First Pass


In the first pass of the Photon Mapping algorithm, photons are randomly shot from the light source. Unlike rays, photons carry flux. That is, each photon carries a small fraction of the light source's energy. Any photon "hit" on a diffuse surface is recorded in the photon map. As mentioned before, any photon that follows a L(S|D)*D - LS+D path will be recorded in the global photon map. Photons that follow a LS+D path are recorded in the caustics photon map.

 

Photon Shooting


Here's an example of a path (LDDD) that a photon can take. First it originates from a light source. Then, it hits a diffuse surface (right wall), and is reflected. Each one of the yellow dots (except for the one in the light source) is a photon hit recorded in the global photon map.


Image courtesy of CS517 (Cornell University).

Just like rays, the flux that the photon carries is adjusted by the BRDF when it interacts with a material. When a photon is reflected, its flux is also divided by the probability of the reflected direction taken. After some number of bounces, the photon will be "absorbed", or terminated by Russian Roulette, on a diffuse surface hit.


Once a designated number of photons are all shot from the light source, the photon map will have a number of recorded hits. The flux stored in the recorded photons vary and depend on the photon's originating light source, what surfaces the photon bounced off of, etc. This information is used in the second pass of the Photon Mapping algorithm.

 

The Global Photon Map


The global photon map stores all L(S|D)*D - LS+D photon hits. Note that the "shadow" region under the spheres have considerably less photon hits. Any photon in the regions are the ones that bounced off of other objects to get there. (Indirect illumination.) Also, notice the color bleeding in the ceiling. The ceiling recieves no direct illumination.


How Photon Mapping Works: Second Pass


The second pass of the photon mapping algorithm is very similar to Monte Carlo ray tracing. Rays are shot from the eye through the image plane into the scene. Direct illumination is computed by sampling area light sources. Eye rays refract and reflect on specular surface hits just as in regular ray tracing.


However, the second pass of the Photon Mapping algorithm use the photon maps whenever appropriate. In path tracing, rays reflect off of diffuse surfaces. However, in photon mapping, a density approximation of the photon map can be performed on a diffuse surface hit instead.


A density approximation gives an estimate of radiance leaving at a point. That is, we can expand an imaginary sphere until it contains N photons. Then, the collective flux of the photons in the sphere is divided by the projected area of the sphere on the surface to give the density approximation. Because we can approximate radiance from the global photon map, it is not necessary to trace rays beyond its first intersection.


It is not hard to see that the density approximation of the caustics photon map will give the contribution from caustics.

 

Final Gathering


The hemisphere at a point is sampled for irradiance. Each ray returns the density approximation at the point of intersection (if it is a diffuse surface). However, if the distance traveled by the ray is too short, a secondary final gather is performed.


Image courtesy of CS517 (Cornell University).


Final Gathering


It turns out that using density approximation to directly estimate radiances off a photon map will not work well. This is because the photon map contains a limited amount of photons, and its distribution varies greatly from point to point. So instead, at an intersection point, a final gathering is performed.


A final gathering is essentially the same as sampling the hemisphere above the point. Once a final gather ray hits a diffuse surface, a density approximation is done to estimate its radiance. However, if the final gather ray travels a short distance, then a secondary final gather is performed at the intersection point.

Rendered Images


 

New Cornell Box with Caustics


A new rendering of the Cornell Box image with amirror ball and a sphere ball. 10,000 global photons and 10,00 caustics photons were used. Fixed photon power scaling, secondary final gathering and various other visual artifacts and bugs. 16 samples/pixels, 63 shadow rays, and 125 final gather rays were used to render this image. Also, I applied tone mapping and supersampled the image. [image size 512x512]

 

Diffuse Cornell Box


Completely diffuse Cornell Box image with 170,000 photons. 9 samples/pixel, 36 shadow rays, 225 final gather rays were used to render this image. Stratified sampling, secondary final gathers are used as well. [image size 1024x1024]

 

Cornell Box with Ward material


This image was rendered using the same parameters as above. Instead of two diffuse spheres, here I use glossy spheres using the Ward model. The isotropic model was used with alpha set to 0.071 (glossy tiles). [image size 1024x1024]

 

Cornell Box with Caustics


Here's an image with a mirror ball and a sphere ball. 10,000 global photons were used, and 10,000 caustic photons were used. Note that the light reflects off of the mirror ball, channels through the glass ball and finally focuses on the right wall. 16 samples/pixel, 49 shadow rays, and 49 final gather rays were used to generate this image. (You still see some noise in it.) [image size 512x512]

 

Cornell Box with a mixture of objects


This scene contains a glass ball, a diffuse ball, and a tile ball (using the Ward model). About 20,000 global photons and 10,000 caustic photons were used. Because the caustic formed by the glass ball is rather large, the density approximation of the caustic photon map has some artifacts in it. To compensate, more photons were used in the approximation in addition to a Gaussian filter. 9 samples/pixel, 25 shadow rays, and 49 final gather rays were used to generate this image. [image size 512x512]



ATFGame's IdIosyncrasy. HTML25. Copyright © 1993-2003 Eugene Lee. Last update: September 14, 2003.