In computer graphics, ray tracing is a technique for generating an image by tracing the path of light through pixels in an image plane and simulating the effects of its encounters with virtual objects. The technique is capable of producing a very high degree of visual realism, usually higher than that of typical scanline rendering methods, but at a greater computational cost. This makes ray tracing best suited for applications where the image can be rendered slowly ahead of time, such as in still images and film and television visual effects, and more poorly suited for real-time applications like video games where speed is critical. Ray tracing is capable of simulating a wide variety of optical effects, such as reflection and refraction, scattering, and dispersion phenomena (such as chromatic aberration). However, for the sake of simplicity my ray tracer only covers reflection. I will be using this skeleton later to incorporate photon mapping, which makes some pretty images. Everything was made from scratch.
- The concept and math behind is actually extremely straighforward. See the wikipedia notes here. The hardest part for me personally when coding the ray tracer ended up being computing the correct ray-to-object intersections post-transformation. Handling the camera and image plane was quite tough too, but it all worked out in the end. - All objects are simply variations of spheres and triangles, rotated, stretched, skewed, and translated using matrices. - Reflections are simply handled by making the main pixel-color computatation method recursive after a bounce, performing another ray calculation and adding the respective rgb values.
The following images were produced from the ray tracer. The first four images demonstrate proper camera and image plane handling - making sure all rays were shooting properly from the camera. The dice was a test to make sure all ray intersections between triangles and spheres were handled properly. The table was used to make sure that shading (inclusive of reflections) were also working. The massive number of spheres demonstrates a proper implementation of AABB trees as an acceleration structure. And finally, the dragon was drawn from parsing an .obj file, generating all triangles, and ray tracing to the utmost efficiency (a few hours?). Also, what kind of person wouldn't attempt to render a Cornell box just for the fun of it?