Ray Trace a Diamond using Photon Mapping

  -- by Tiffany Inglis

The goal is to make a ray tracer that incorporates photon mapping in order to model lighting effects exhibited by a diamond. The base style for this demo page was copied and pasted from here. The Cornell Box data was obtained from here with slight modifications (because I didn't implement area lights)


1 - Photon map


A map of the photons stored in the scene

2 - Nearest neighbour search by kd-tree

Timing Data: Naive algorithm vs Kd-tree nearest neighbour search

Suppose we have an 100x100 image (10000 pixels) and for each pixel's primary ray intersection with the scene, we need to find its 100 nearest photons. Let's vary the number of photons used in the photon map, and see how well the naive algorithm and the kd-tree algorithm perform in finding the nearest neighbours:

With 1000 photon casted:
  naive: 1.67 seconds
  kd-tree: 0.39 seconds

With 10000 photon casted:
  naive: 17.54 seconds
  kd-tree: 1.60 seconds

With 100000 photon casted:
  naive: 167.84 seconds
  kd-tree: 20.09 seconds

3 - Filtering photons


Each pixel is coloured according to the intensity of photons around it. Notice the diffuse
reflection off the red and green walls onto the white wall.

4-5 - Reflection, transparency and refraction


Spheres with increasing reflectance (0.1 to 0.5 to 0.9)

Spheres with increasing transmittance/transparency (0.1 to 0.5 to 0.9)

Transparent spheres with increasing indices of refraction (1.2 to 2 to 10)

Mirror and glass spheres in the Cornell Box

6 - Additional primitives


Cylinder, cone and torus

7 - Constructive Solid Geometry


Unions (head and torso), differences (ears) and intersections (hands) of spheres

8 - Texture Mapping


Aliens got tired of abducting macho cows

9 - Anti-aliasing by stochastic sampling


Before anti-aliasing

Pixels requiring anti-aliasing are highlighted in cyan

After anti-aliasing

10 - Final Scenes


Abstract NPR diamond

Spinning "diamond"

Actual diamond!!! Now let's see if it exhibits the hearts and arrows phenomenon

In motion

Top view (partial arrows)


Bottom view (no hearts)


11 - Bugs I encountered


texture gets blended in photon mapping

some problem with local/global variables

mirror reflection bug

incorrect use of nearest neighbours

this is probably not right, but I have no intuition for glass tori

Supposed to be a metal sphere I think

Diamond with baguette cut. This is not really a bug but
I ran out of time to make it look nice.

ahh huge bug!