This project is based on the book Ray Tracing in One Weekend by Peter Shirley. I decided to use the code to generate atom-inspired animations. In this first animation, "core" spheres are metal and reflect light from the "electron" spheres. More animations below.
- New Scene class using variadic templates for controlling the lifetime of Hitables and Materials.
- Templated vec3 class.
- Simple Image class for writing the output to disk.
- PNG output using stb_image_write.h library.
- Unit testing using Catch2 library (only for vec3 at the moment).
- Parallel rendering with std::async.
- Random number generation with <random> header.
- General refactoring and style changes to my own liking.
Profiling this code on Visual Studio 2017, I realized that the bulk of the computation happens (unsurprisingly) in the first couple of lines of the Sphere.hit() function. Most of the time, the ray does not hit the sphere, the hit() function returns at the first if statement and no expensive color computation is needed with that sphere.
I obtained a significant speedup in Visual Studio 15.0 (close to ~100% in a simple scene) by making Ray.origin() and Ray.direction() return const references, which avoids multiple copy operations in the critical code section.
In the second animation, the "core" spheres are glass with refractive index 1.5. The center looks strange because the spheres overlap in the middle and the code cannot handle that properly.
In the third animation, I raised refractive index to 2.0, which results in stronger total internal reflection and peculiar symmetrical regions where light passes through the "core".
The book's original code by Peter Shirley is in the public domain. This project is licensed under the MIT license. See also DEPENDENCY_LICENSES.txt.