Skip to content

Latest commit

 

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Path Tracer

Various implementations for the final scene from Ray Tracing in One Weekend:

Performance

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.

Built-in C++ render OSL render Metal render
CPU · Built-in C++ CPU · OSL GPU · Metal

GPU Path Tracer

Requirements

The GPU renderer requires macOS and the Xcode command-line tools. metal-cpp is vendored in this repository.

xcode-select --install

Build

From the project root:

cmake -S . -B build/gpu -DBUILD_GPU_PT=ON -DBUILD_CPU_PT=OFF
cmake --build build/gpu

BUILD_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.

Run

./build/gpu/gpu_pt > output.ppm

CPU Path Tracer

The 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 .oso files at build time.

OSL support is optional and adds no OSL dependencies to a built-in-only build.

Requirements

The CPU renderer requires oneTBB:

brew install tbb

The OSL backend also requires compatible OpenShadingLanguage and OpenImageIO installations.

Build

For built-in shading only:

cmake -S . -B build/cpu -DBUILD_CPU_PT=ON
cmake --build build/cpu

To 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/cpu

CMake 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.

Run

./build/cpu/cpu_pt > output.ppm

An 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

References

About

The classic "Ray Tracing in One Weekend", extended with an OSL backend and separately with an Apple Metal implementation.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages