All work

Engineering · C++17 · 2025

Retsu

A ray tracer from scratch in C++17, with a scene format and a parser of its own. Analytic intersections, recursive reflection, hard shadows, supersampling and an OpenMP render loop. No graphics or maths library.

Role
Lead developer, team of three
Stack
C++17 · OpenMP · SFML
Proof
16.3 s down to 3.7 s on four cores
Links
GitHub
Spheres, a cone and a capped cylinder on a reflective floor, rendered by Retsu

What it does

Four primitives, sphere, plane, finite capped cylinder and finite cone, each intersected analytically. Ambient, point and directional lights, Lambertian shading, hard shadows from shadow rays, and recursive reflection to a configurable depth. Optional supersampling smooths the edges, and scenes are written in a small INI-like format with its own tokenizer and parser.

Performance

Every pixel is independent and nothing is shared for writing, so the row loop is a single OpenMP parallel region with no synchronisation. On four physical cores, a heavy scene at sixteen rays per pixel drops from 16.29 to 3.67 seconds, a 4.4× speedup.

The loop uses dynamic scheduling rather than a static split. A row of empty background costs almost nothing while a row crossing mirrored surfaces costs several bounces, and a static split would leave cores idle waiting for the unlucky ones.

Two decisions worth pointing at

No type queries in the hot loop. Each light answers for itself through the interface, instead of the renderer asking every light what it is, at every pixel, several million times per frame. And the image is one flat buffer rather than a vector of rows, which keeps the sequential access the renderer performs friendly to the cache.

Notes from the cleanup

Bringing the project to its current state turned up four bugs worth naming. Reflection was declared but never wired: the trace function accepted a depth and never called itself. The cone normal was wrong in two ways at once, so cones rendered as flat black silhouettes. The directional light pointed backwards and contributed nothing. And the build without the preview window did not compile.

Credits

A three-person project, first built as a school assignment. I wrote the renderer, the intersection maths, the scene parser and the factories, and did the cleanup above. Halim Sonou-Agossou worked on primitives and build integration, and Omonlola on scene authoring and testing.