Ray Tracer
A multithreaded CPU ray tracer in modern C++. A thread pool keeps every core busy, a BVH with Möller–Trumbore triangle tests keeps traversal fast, and Monte-Carlo GI with photon and caustics maps handles the light transport.
Overview
I built a CPU ray tracer in modern C++ from scratch. It grew from basic shading into a physically inspired renderer with Monte-Carlo global illumination and photon mapping. Along the way, performance work became as important as the lighting itself. A thread pool spreads the render across every core, a BVH with Möller–Trumbore triangle intersection keeps traversal cheap, and I profiled the hot paths and tuned them iteratively to cut render times.
Architecture
The renderer runs in two passes. First, photons are shot from the lights, bounced through the scene, and stored in a photon map. Then camera rays are traced for each pixel. At each hit point, direct light (with soft-shadow sampling), indirect light (Monte-Carlo), and caustics (estimated from nearby photons) are combined, and many samples per pixel are averaged into the final color.
Deep Dive
Acceleration: the BVH
Testing every ray against every object doesn’t scale. The scene’s geometry is organized into a bounding volume hierarchy, a tree of boxes, so each ray only tests the few primitives whose boxes it actually passes through. Both passes rely on it, so it pays off twice. At the leaves, triangles are tested with the Möller–Trumbore algorithm, which computes the hit and its barycentric coordinates in one pass without precomputing a plane equation.
I profiled traversal and intersection as the hottest paths in the renderer and tuned them iteratively, measuring each change against render time.
Global illumination & photon mapping
Indirect lighting is estimated with Monte-Carlo sampling: secondary rays bounce in random directions and their contributions are averaged. That’s what gives the Cornell box its red and green color bleeding. Caustics, the light focused through glass, are hard to find with random sampling, so photon and caustics maps handle them. Photons follow the light forward, and the renderer estimates their density at each hit point.

Soft shadows, glossiness & anti-aliasing
Area lights are sampled many times per shading point to produce soft shadow edges. Glossy surfaces scatter their reflection rays, and multiple jittered samples per pixel smooth out aliasing. Depth of field uses the same sampling idea, applied to the camera’s lens.

Multithreading
Rendering is embarrassingly parallel: each pixel is independent. Render work is fed to a thread pool sized to the machine, so every hardware thread stays busy and render time scales with core count.
Results & Learnings
- Built end to end from first principles, from ray-object intersection math up to Monte-Carlo GI and photon-mapped caustics.
- Profiling made performance a measured loop: every change to traversal and intersection was checked against render time.
