chromapath

GPU-accelerated path tracer implementing 'Ray Tracing in One Weekend' with CPU, Vulkan compute, and hardware ray tracing backends


Keywords
gpu, path-tracer, raytracing, rendering, vulkan
License
GPL-3.0

Documentation

ChromaPath - Ray Tracing in One Weekend: Rust & Hardware RT

ChromaPath Output

ChromaPath is a complete Rust implementation of Peter Shirley's "Ray Tracing in One Weekend" with GPU hardware ray tracing acceleration.

What is this?

This project implements the exact same path tracer from the famous book, but with two key improvements:

  • Pure Rust: Using modern Rust idioms and the glam math library
  • Hardware RT: Optional GPU acceleration using Vulkan ray tracing extensions

Both implementations produce identical images - the GPU version is just orders of magnitude faster!

Quick Start

# Install dependencies (Vulkan SDK required for default GPU mode)
# Then build and run:

# Hardware RT (default, orders of magnitude faster)
cargo run --release -- -s 100

# CPU mode (naive book implementation, for comparison/learning)
cargo run --release -- --cpu -s 100

# Compare both with benchmark
cargo run --release -- --bench

Performance

The GPU hardware ray tracing version delivers orders of magnitude performance improvements over the naive CPU implementation, especially for complex scenes with many objects.

Real-world Example

RTX 3090, 800×600, 4000 samples per pixel, complex scene with Lucy model (448k triangles) + random spheres

🚀 Hardware Ray Tracing: 11.43s
   ├─ Ray tracing dispatch: 4.40s (436.6M rays/sec)
   ├─ Scene setup: ~2s
   └─ Image readback: ~5s

📊 Performance: 436.6 million rays per second
🎯 Total pixels: 480,000 (4000 samples each = 1.92 billion rays)

The same scene on CPU would take days due to the naive O(n) intersection testing without acceleration structures.

Output Formats

# PNG output (hardware RT is default)
cargo run --release -- -s 100 -o image.png

# HDR/EXR for professional workflows  
cargo run --release -- -s 100 -o image.exr

# Send directly to TEV viewer
cargo run --release -- -s 100 --tev

# CPU mode for comparison
cargo run --release -- --cpu -s 100 -o cpu_image.png

How it works

The CPU implementation faithfully follows "Ray Tracing in One Weekend":

  • Same sphere scene from Chapter 1
  • Same camera, materials, and ray tracing logic
  • Deliberately naive: No BVH, no advanced optimizations - just like the book
  • Simple linear search through all objects (O(n) complexity)
  • Perfect for learning, but slow for large scenes

The GPU version translates these concepts to Vulkan hardware RT:

  • ray_color() function → Ray generation + hit/miss shaders
  • Manual ray-sphere intersections → Hardware acceleration structures (O(log n))
  • CPU loops → GPU parallel execution across thousands of cores
  • Massive speedup comes from both parallelization AND better algorithms

Requirements

  • Rust 1.70+
  • Vulkan SDK (for hardware RT mode)
  • GPU with RT support (RTX 20xx+ or RDNA2+) for hardware acceleration

Book Chapters Implemented

Chapter 1: Output an Image
Chapter 2: The vec3 Class → glam::Vec3A
Chapter 3: Rays, a Simple Camera
Chapter 4: Adding a Sphere
Chapter 5: Surface Normals and Multiple Objects
Chapter 6: Antialiasing
Chapter 7: Diffuse Materials
Chapter 8: Metal
Chapter 9: Dielectrics
Chapter 10: Positionable Camera
🚀 Bonus: Hardware Ray Tracing with Vulkan

References