This project attempted to create an efficient method of generating rainbows projected through a prism without using photon mapping. Written from scratch in C# with no graphics libraries, I learned a lot about ray tracing processes during development. The basic ray tracer creates multiple rays per pixel that transmit through and reflect off of geometry in the scene. It can load in geometry from files, and uses a simple KD Tree implementation for optimization purposes.The main challenges of this project were representing the full spectrum of light and calculating the diffraction of light through the prism.
Instead of a basic RGB color value, each ray has a component for each wavelength of light. Each wavelength was associated with an RGB value according to the Mihai-Strajescu approximation. When rays encounter a refractive surface each wavelength splits off and is traced separately. This diffraction creates the rainbow effect on the spheres as observed in the image to the right.
To generate a projected rainbow effect, a rectangular light source with uniform direction was placed in the scene. When this light hits the prism, it diffracts into several different colors, specified by a run-time parameter. Based on the refractive index of the prism, a new light source volume is generated for each wavelength of light. When a ray intersects a surface in one or more of these volumes, the ray receives additional lighting of that wavelength.
The success of this method proved limited. The generated volumes were reasonably accurate in this test case, but were inaccurate in scenarios where they intersected more than a single side of the prism. Additionally, these volumes did not interact favorably with KD trees, unlike photon mapped solutions. Another problem is that the time required to render a scene scales directly with the number of wavelengths approximated. Despite these limitations, this project was academically interesting and dramatically expanded my understanding of raytracing