Now, I will show the implementation of reflection (from the Whitted approach). It is basically using the reflection law and recurse the ray cast.

Reflection rays

Each object can reflect a ray more or less from a different object. A mirror would reflect the light totally, and a matte object would reflect nothing. Each new reflection is a new ray tracing call, so it can be costly. The number of recursion levels will be fixed, even if an object reflects nothing: this will be implemented through shaders in the future.

Read More

Adding the lights is the first step toward a Whitted raytracer. For each ray that hits an object, several rays can be cast, reflection, refraction and shadow. The last one is the one created with lights.

Lights and shadow rays

Without light, objects are bland, seem to have no depth, … Light on a scene can be cast by several light sources. When a ray of the camera hits an object, the intersection point can be illuminated by one or several of those sources. Each of them contributes to the color of the object. If the light source direction is parallel with the normal of the object at the intersection point, the contribution will be maximum. If it is orthogonal, the contribution will be zero. The scalar product is the tool used to compute this quantity.

Read More

C++ code quality is a difficult topic. There are some basic topics and other, more advanced. Sutter and Alexandrescu wrote a complete book on C++ standards to achieve good quality with basic and advanced topics, but Meyers wrote a book before, on the basics of C++.

Effective C++ is at its third edition, which is a complete rewrite with topics from the “old” Effective C++ and More Effective C++. So if you have one or the other, you will find yourself with additional content.

Read More