This is a multi-threaded ray tracer based on the first book of Ray Tracing in One Weekend book series by Peter Shirley, Trever D Black and Steve Hollasch. You can find all the books here.
The original book focuses on core concepts and a naive implementation, intentionally leaving room for optimization. I have extended the codebase to support CPU-based multi-threading, achieving over 10x performance improvement on a 16-core CPU.
- Multi-threaded Rendering: Uses
std::for_eachwithstd::execution::parto saturate all available CPU cores. - Primitives: Sphere intersection math.
- Materials:
- Lambertian: Matte textures with accurate light diffusion.
- Metal: Reflective surfaces with adjustable fuzziness.
- Dielectric: Refractive materials (glass, water) with Schlick approximation.
To build this project, you will need:
- C++ Compiler: Must support C++17 (e.g., MSVC, GCC, Clang).
- CMake: Version 3.23 or higher.
- Intel TBB (Thread Building Blocks): Essential for
<execution>support on many compilers (especially MinGW).- MinGW users: Install via
pacman -S mingw-w64-x86_64-tbb
- MinGW users: Install via
-
Clone the repository
git clone https://github.com/ujjwalvishwakarma2006/multi-threaded-ray-tracer cd multi-threaded-ray-tracer -
Configure (Ninja generator recommended for speed)
cmake -B build -G Ninja
-
Build
cmake --build build
-
Render The application outputs PPM image data to standard output (stdout).
# Windows .\build\RayTracer.exe > image.ppm
To see the time taken for rendering, you can use:
.\render_image.ps1 image.ppm
- GPU Acceleration (CUDA/OptiX)
- Real-time viewport
- Complex mesh support (Triangles/OBJs)
This project is hand-written and maintained by me.