Various implementations for the final scene from Ray Tracing in One Weekend:
- GPU Path Tracer
- Apple's Metal API through metal-cpp
- CPU Path Tracer
- Built-in RTIOW C++ shading backend
- OSL shading backend
Measurements used a 1200 x 675 image at 500 samples per pixel, on an 8-core
M1 MacBook Pro:
| Renderer | Shading | Parallelism | Traversal | Time | Speedup |
|---|---|---|---|---|---|
| CPU | Built-in C++ | Single-threaded | Linear | 6h 06m 44s | 1x |
| CPU | Built-in C++ | Multithreaded | Linear | 53m 42s | 6.8x |
| CPU | Built-in C++ | Multithreaded | BVH | 1m 57s | 188x |
| CPU | OSL | Multithreaded | BVH | 2m 27s | 150x |
| GPU | Metal | GPU-parallel | Linear | 2m 28s | 149x |
See OSL_Integration.md for details.
![]() |
![]() |
![]() |
|---|---|---|
| CPU · Built-in C++ | CPU · OSL | GPU · Metal |
The GPU renderer requires macOS and the Xcode command-line tools. metal-cpp is
vendored in this repository.
xcode-select --installFrom the project root:
cmake -S . -B build/gpu -DBUILD_GPU_PT=ON -DBUILD_CPU_PT=OFF
cmake --build build/gpuBUILD_CPU_PT defaults to ON, so leaving it out here would also configure
cpu_pt and require oneTBB.
CMake compiles src/gpu/Shaders/*.metal into build/gpu/default.metallib,
beside the executable, where the renderer looks for it.
./build/gpu/gpu_pt > output.ppmThe CPU renderer shares its geometry, BVH, camera, and threading between two material backends:
--builtin: C++ materials modeled on the book.--osl: OSL shaders compiled to.osofiles at build time.
OSL support is optional and adds no OSL dependencies to a built-in-only build.
The CPU renderer requires oneTBB:
brew install tbbThe OSL backend also requires compatible OpenShadingLanguage and OpenImageIO installations.
For built-in shading only:
cmake -S . -B build/cpu -DBUILD_CPU_PT=ON
cmake --build build/cpuTo include OSL shading, point CMake at the OSL and OpenImageIO installations if they are not already on its search path:
OSL_ROOT=$HOME/projects/OpenShadingLanguage/dist
OIIO_ROOT=$HOME/projects/OpenImageIO/dist
cmake -S . -B build/cpu -DBUILD_CPU_PT=ON -DENABLE_OSL=ON \
-DCMAKE_PREFIX_PATH="$OSL_ROOT;$OIIO_ROOT"
cmake --build build/cpuCMake compiles src/cpu/osl/shaders/*.osl into build/cpu/shaders/*.oso. If the
executable fails to start with a Library not loaded error, add the missing
library's directory with -DPT_OSL_EXTRA_RPATHS=/path/to/lib.
./build/cpu/cpu_pt > output.ppmAn OSL-enabled build defaults to --osl. Select a backend explicitly when
comparing the two:
./build/cpu/cpu_pt --osl > osl.ppm
./build/cpu/cpu_pt --builtin > builtin.ppm- Ray Tracing in One Weekend
- GPU Programming with the Metal Shading Language
- Accelerated Ray Tracing in One Weekend in CUDA
- testrender, OSL's reference renderer integration


