Chapter 1: Introduction

This text and the included C++ source code provide a demonstration of a 3D graphics technique called ray tracing. Ray tracing mathematically simulates the behavior of light and its interactions with physical objects — reflection, refraction, and shadows. Sophisticated ray tracing techniques make possible realistic special effects for movies and games, as well as helpful visualizations of organic molecules for biologists and machinery designs for mechanical engineers. The field of ray tracing has grown extremely complex over the past three decades, as everyday computers have grown exponentially in speed and memory capacity.

My goal in this tutorial is to provide a starting point that omits as much complexity as possible, and assumes only that the reader has a good understanding of algebra and analytic geometry. I include a review chapter on vectors for those who need it; vectors are of primary importance in ray tracing. Some trigonometry will be helpful at times, but only in small doses, and the necessary parts will be explained. To follow the programming examples, the reader must also understand the C++ programming language. By following along with this text and the C++ code that accompanies it, you will understand core concepts of computer graphics sufficiently to build your own mathematical models and see them transformed into 3D images.

To keep things simple, I will limit the covered topics in certain ways. The shapes we will draw will be simple geometric solids like spheres, cubes, and cylinders, not complex artistic endeavors like people or animals. (However, we will be able to combine the simple shapes in interesting and even surprising ways within a single image.) All light sources will be modeled as perfect points, resulting in unnaturally crisp shadows — we thus avoid a tremendous amount of complexity for diffuse light sources and mutual reflections between objects in the scene.

In spite of some limitations, the source code provided with this book has quite a bit of flexibility in its modeling of optics. Objects can combine glossy reflection, diffuse scattering, and transparent refraction. Ray-traced images can thus possess visual appeal from realistic shading, perspective, lensing, and sense of depth, as shown in Figures 1.1 and 1.2. By default, an object has uniform glossiness, opacity, and color across its surface, but the programmer has the ability to derive custom C++ classes that override this behavior, allowing a single object to have varying features across its surface.

To keep distractions to a minimum, I will limit the programming examples to the command line. I want to present ideas and algorithms that you can experiment with whether you are using Microsoft Windows, Mac OS X, or Linux. All three operating systems have very different and complicated programming models for their respective graphical user interfaces (GUIs). But they all have a very simple and similar way of writing command line programs. Instead of trying to render images in a GUI window, the source code accompanying this book generates an image, saves it to an output file, and exits. After the program has finished, you can use an image viewer or web browser to look at the output file. You can then modify the source code, build and run the program again, and see how the output changed.

Overall, my goal is to make the fundamentals of ray tracing understandable. There are many places in this book where an expert on the subject could fairly say, "there is a faster way to do that" or "a more sophisticated approach is possible," but in every case where I have had to make a choice, I have leaned toward making this as gentle an introduction as possible to computer graphics. In some cases, I have left out certain optical subtleties needed to make completely photo-realistic images, and in other cases I have implemented an algorithm in a slower than ideal way; but in every such case, the resulting C++ code is smaller and simpler to read and digest. My hope is that this book therefore provides a helpful bridge to newcomers to the field of ray tracing who want to understand more than vague concepts but are put off by the overwhelming complexity of academic journals and postgraduate-level textbooks. In this regard, I will consider Fundamentals of Ray Tracing a success if readers find that it satisfies their curiosity without frustrating them, and if some are intrigued into pursuing more advanced treatments of the subject that otherwise would have been too intimidating.

 Figure 1.1: A ray-traced image.

 Figure 1.2: Another ray-traced image.