CS580: Advanced Graphics
Photon mapping is one of the best and fastest methods in computer graphics to simulate various effects such as indirect illumination, caustics and sub surface scattering.
Method & Implementation:
My photon mapper currently supports the following features:
- Indirect Illumination
- Reflective Caustics
- Soft Shadows
- Final Gathering
- Triangle Smoothing
- Diffuse, Specular, Refraction, Reflection
- MilkShape 3d Ascii triangle meshes
Key missing features:
- Projection maps for fast casting
- Refractive Caustics
- Volume rendering / Volume photons
- Textures, Bump Maps, Displacement...
- Fast triangle data structure for raytracing
A quick pseudocode is as follows, for all details look at Henrik Jensen's paper or book.
1. Cast photons into scene from lights and record object intersections. Only add photons to the photon map once they have already collide with one diffuse surface(to prevent double counting direct illumination).
2. Recursively construct a KDTree heap of the photon map by splitting the photon list into 2 halves. The splitting dimention is the longest axis that bounds the current list of points.
3. Raytrace the scene and at each pixel intersection also compute the indirect illumination by looking at the photon heap. Perform the search by recursively traversing the kdtree keeping a priority queue of the nearest n photons within a certain distance. Then use the n nearest photons to estimate the contribution of the indirect illumination with this formula indirect = constant*sum(nearest n photon power * objectColor)/(pi*maxDist*maxDist*totalNumPhotons).
Here are some sample renders. The order is standard ray tracing, opengl photon map, rendered photon map.
*note this image was adjusted in photoshop for because i felt the photonmap render was overexposed.
Source Code & Excecutable:
Unfortunetly my photon mapper currently does not have a gui, all parameters have to be set in the include.h file and then recompiled. The program reads 2 files, the cs480 raytracer lights / camera file (only point lights are supported) and an milkshape 3d ascii export file for the model / material information. The format of the materials is as follows, (materials are at the end of the ascii file)
Here is a link to the source code and several example model files / camera files.
Though my implementation can produce realistic images it suffers from the lack of a good data structure for ray triangle intersection, it uses bounding boxes but nothing further to accelerate intersection. Also my soft shadow implementation is very slow, so if you are testing the code make sure to turn soft shadows off, but turn them on in final renders because they do look nice. If i had more time I would first improve my ray triangle intersection, then I would get refractive caustics to work, and finally I would read some papers on how to create fast soft-shadows.
References / Credit:
Henrik Wann Jensen. Global illumination using photon maps". Rendering Techniques '96
Ascii File Loader / OpenGL Renderer: Ronny André Reierstad , www.morrowland.com
Smooth Triangle Interpolation: http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64468
Ray Triangle Interseption: www.softsurfer.com