Raytracer
A toy software raytracer for learning. Written in C++.
Overview
I wrote a toy software raytracer for learning purposes based on Peter Shirley’s excellent article, Ray Tracing in One Weekend. I’ve implemented some additional features of my own to improve performance including:
- Multithreaded image rendering.
- SIMD acceleration.
- Fast random float generation.
- BVH acceleration of the scene.
Multithreading
When implementing multithreading, I wanted to make sure that my solution would scale well no matter how many cores I threw at it, and would minimize the amount of waiting that would need to be done.
My solution was to have each thread render an entire image, but distribute the samples across the threads, and then average the images at the end. For example, if you wanted to use 8 threads and 512 samples per pixel, each thread would render an entire image using 512 / 8 = 64
samples.
SIMD and Randomness
I have two code paths for SIMD and non-SIMD math which can be toggled using a flag in common.hpp
.
When choosing a random float algorithm, I only cared about speed as long as the resulting image looked good at a glance. After some testing, I settled on Xoroshiro128+.
Room For Improvement
As always, I’m constantly looking for ways to improve the codebase. Some ideas I have currently include:
- Support for triangle meshes, textures, and light sources.
- Rendering multiple images to create GIFs.
- A more efficient BVH generation algorithm.