Ray Tracing / Photon Mapping Project


In Fall 2005, I took a Computer Graphics course. It focused on how to model and generate realistic 3D graphics, with a focus on ray-tracing. Ray-tracing is a technique whereby a 3D scene is rendered (in 2D) by (usually backwardly) tracing light rays from the observer, to the object, and then to the light source. It is somewhat similar to viewing an image on a plate-glass in a large-format film camera.

We were given a basic framework for implementating a ray-tracer and during the course, we added various capabilities including:

Simply put, the application of simple physics (reflection,refraction,etc) and geometry (ray-object intersections) produced a fairly impressive ray-tracer. As an example, the following image was rendered on my implementation:

Photon Mapping Introduction

One classic design for ray-tracers casts backward rays. What is backward about this design is that rays are cast from objects towards lights. In the physical world, most light "rays" do not travel towards the viewer (they hit other things). Hence, by only computing rays that are directly observable by the viewer, this method is computationally efficient (the only rays traced are the visible ones).

While this method is capable of producing fairly realistic images, it has one short-coming. Transparent objects generally have a different index of refraction than their surrounding medium. This difference in refraction index causes light to be focused. Which means photons arriving from different directions may be focused onto a single point or region, resulting in a bright spot known as a caustic. The classic design for ray-tracers mentioned in the previous paragraph cannot render caustics.. (They simply show ordinary illumination where the caustic should appear).

Henrik Jensen proposed a novel way of rendering caustics in 1995. For simplicity, this discussion will only be concerned with point-light sources, but Jensen describes how to use his method for a variety of light sources and arbitry BRDFs. His method invovles two phases. In the first phase, individual photons are modeled and cast from random directions from each light source. Collisions with photons and scene objects are stored in a photon map. The photon map stores the photon's direction, energy, and position. In the second phase, the brightness of each point in the scene is estimated by density of photons in a small region. Jensen shows that as the number of photons simulated increases, the brightness estimates become accurate.

Jensen also points out that it is not necessary to use photon-mapping for all illumination. Normal ray-tracing can be used to compute most of the scene illumination and the photon map can be used to render caustics. This provides both significant computational savings as well as a cleaner-looking image.

Simply put, photon mapping is a simple techique that statistically approximates global-illumination.



I added photon mapping to the previous assignment's ray-tracer. For performance reasons, the photon uses a KD-tree for storage. Only photons that have undergone refraction are stored in the map. Balancing is performed all photons have been cast, resulting in a perfectly balanced tree. For all other lighting, standard backward ray-tracing is used.

For point light sources, photon-mapping inherently obeys the Inverse-Square law. This caused a problem in the provided scenes. They used light sources whose brightness diminished at a linear (rather than quadratic) rate. As a remedy, I implemented histogram equalization to compensate for scenes that would otherwise appear dimly illuminated.

Example Images

Note the caustic appearing underneath the sphere. The light source is actually above the sphere (though not visible). The sphere is not completely transparent, hence it appears to glow.

There is a mostly-transparent sphere (just off-camera) that is causing light to be focused onto the large sphere. The faint shadow of the non-visible spehere can be seen. The bright spot is a caustic. This effect is similar to that of holding a magnifying glass in the sun.


Realistic Image Synthesis using Photon Mapping
Henrik Wann Jensen
ISBN: 1-56881-140-7. AK Peters, 2001
2nd printing with corrections, March 2005