RAY TRACER

Ray tracing is an image-synthesis method based on the principle of simulating light rays bouncing around - just as they do in reality. I first came in contact with ray tracing and global illumination models during a computer graphics course. As part of the practical assignments we were required to program our own physically-based ray tracer, but even after the course was over I continued spending time improving it from time to time.

In the end, what started out as an assignment turned into quite a big project. Over time, with numerous rewrites and additions, my pet ray-tracing library has now become one of my favorite projects to work on.

Table of contents

Showcase

Ray tracing basics

Ray tracing is all about simulating real light transport. Here's the gist of it: At the start of its journey, a light ray leaves the light source. At this point, it is charged with a certain amount energy across different wavelengths. Upon collision with an object, energy across certain wavelengths may be absorbed, scattered, reflected, refracted or some combination of these.

This spawns countless new, secondary light rays who travel through the scene in the same manner until colliding with an object, and the process repeats. Eventually, some rays reach the viewer's eye, where the energy they carry across the spectrum is sensed and translated into an image.

If we could simulate and track the journey such a ray made from light source to eye we could compute its energy values when it reaches the eye and therefore its color, simply by accounting for all objects it hit along the way and subtracting the energy they absorbed.

Figure 1: We can compute a ray's color by simulating its journey from the light source to the observer's eye.

Path tracing

Path tracing is a ray tracing method that performs the light ray simulation backwards: i.e. rather than starting at the light source and ending at the virtual camera, we start at the camera (or more precisely, on the camera's image plane) and trace the ray's journey backwards until we hit a light source. Of course, the detailed procedure is not as straightforward as that, but we won't be discussing it here, especially since the internet is filled to the brim with excellent resources about path tracing and ray tracing in general.

Source code

You can view the source code and documentation on GitHub. Some simple scene configurations are available under the demo directory of the repository.

See also