A. Alekseev
All projects

CSG ray tracer

University

A C++17 ray tracer that renders JSON scenes built with constructive solid geometry. University team project, graded 20/20 with maximum bonus points.

Team of three, TU Hamburg, Object Oriented Programming course

  • Framed mirror with second-order reflections

  • Glass tori, metal and a puddle with an uneven edge

  • Glass of different thickness refracting a striped floor

  • Neon tunnel animation built from CSG frames

What I built

  • Everything is a Solid with two methods, intersect(ray) and contains(point). Primitives, boolean operations and transforms all implement it (Composite pattern), so CSG nests without limit and a new primitive only needs those two methods.
  • Spheres, half-spaces and tori, including a custom quartic solver for the torus. Union, intersection, difference, exclusion and negation reduce to an algebra of sorted ray intervals.
  • Recursive shading: reflection, refraction by Snell’s law with total internal reflection, shadows, Phong lighting, jittered anti-aliasing. Multithreaded rendering cut the showcase scene from 5.3 s to 1.1 s on 12 cores.
  • Unit tests for every module check properties rather than magic numbers, e.g. a glass sphere must flip the background upside down. Every JSON scene runs as a regression test in CTest, with AddressSanitizer and UBSan builds.
  • Multi-stage Docker build pinned by digest that runs the tests with GCC and -Werror during the build, about 360 MB final image running as a non-root user.
  • Python bindings via pybind11 and ffmpeg scripts for animations, Doxygen API docs and UML class diagrams.

Tech stack

Core

  • C++17
  • Eigen
  • nlohmann/json
  • std::thread

Build and tests

  • CMake
  • doctest
  • CTest
  • AddressSanitizer
  • UBSan

Tooling

  • Docker
  • pybind11
  • Python
  • ffmpeg
  • Doxygen
Next projectRelinxr