A high-performance path tracing renderer with CPU, GPU, and real-time interactive implementations
Try it online: Live WebGPU Raytracer
Run locally:
git clone https://github.com/tchauffi/rust-rasterizer.git
cd rust-rasterizer
cargo run --bin live_raytracer --releaseUse your mouse to rotate the camera and press SPACE to toggle rendering modes!
This project demonstrates three different approaches to ray tracing - a rendering technique that simulates how light behaves in the real world to create photorealistic images:
- 🖥️ CPU Raytracer - Traditional software rendering with full path tracing
- ⚡ GPU Raytracer - Hardware-accelerated offline rendering using compute shaders
- 🎮 Live GPU Raytracer - Real-time interactive raytracer you can navigate and explore
Whether you're learning about ray tracing, exploring Rust graphics programming, or looking for a starting point for your own renderer, this project provides working examples of multiple rendering approaches.
- Multiple Rendering Backends: Choose between CPU, offline GPU, or real-time GPU rendering
- Path Tracing: Physically-based lighting with multiple light bounces for realistic illumination
- Mesh Support: Load and render complex .obj models with triangle meshes
- HDR Environment Maps: Support for high dynamic range .exr skyboxes
- Interactive Controls: Real-time camera navigation with mouse controls
- WebAssembly Support: Runs in the browser using WebGPU
- Multiple Materials: Diffuse, metallic surface properties
- Acceleration Structures: BVH for efficient ray-mesh intersection
- Progressive Rendering: Denoising and sample accumulation for high-quality images
The CPU version renders scenes using traditional CPU-based raytracing and outputs to a PPM image file. Best for learning how raytracing works under the hood.
# Build and run (outputs to stdout, redirect to file)
cargo run --release > output.ppm
# Or build first, then run
cargo build --release
./target/release/rust-raytracer > output.ppmUse this when:
- Learning raytracing fundamentals
- Debugging rendering algorithms
- No GPU compute support available
Features:
- Full path tracing with multiple bounces
- Direct and indirect lighting
- Mesh support (.obj files)
- Sphere primitives
The GPU version uses compute shaders to accelerate rendering, outputting to a PPM file. Significantly faster than CPU rendering for high-quality images.
# Build and run
cargo run --bin gpu_raytracer --release > output.ppm
# Or build separately
cargo build --bin gpu_raytracer --release
./target/release/gpu_raytracer > output.ppmUse this when:
- Rendering high-quality final images
- Need faster rendering than CPU
- Don't need real-time interaction
Features:
- GPU-accelerated compute shader rendering
- Same scene quality as CPU version
- Significantly faster rendering times (10-100x speedup)
- Hardware-accelerated ray-triangle intersection
The live version provides a real-time interactive window where you can navigate the scene. Perfect for exploring scenes and iterating on designs.
# Run the live raytracer
cargo run --bin live_raytracer --releaseUse this when:
- Exploring and navigating scenes interactively
- Setting up camera angles for final renders
- Demonstrating raytracing in real-time
- Debugging scene geometry
Controls:
- Mouse: Click and drag to rotate the camera
- SPACE: Toggle between raytracing and normals visualization modes
- Window Title: Displays current mode and FPS
Features:
- Real-time GPU raytracing (30-60 FPS on modern GPUs)
- Interactive camera controls
- Two rendering modes:
- Raytracing: Full path tracing with lighting and shadows
- Normals: Fast visualization showing surface normals (useful for debugging)
- Live FPS counter in window title
- WebAssembly support for browser-based rendering
- Rust: Latest stable version (install from rustup.rs)
- GPU versions: A GPU with compute shader support
- Vulkan (Linux, Windows, Android)
- Metal (macOS, iOS)
- DirectX 12 (Windows)
- Web version: A browser with WebGPU support (Chrome 113+, Edge 113+, Firefox with flag)
The project can be built for WebAssembly and deployed to GitHub Pages:
# Install trunk (if not already installed)
cargo install trunk
# Build for web
trunk build --release
# The output will be in the dist/ directoryPerformance varies based on hardware and scene complexity:
| Renderer | Resolution | FPS/Time | Notes |
|---|---|---|---|
| CPU | 1920x1080 | ~30-60s | Single-threaded, full quality |
| GPU Offline | 1920x1080 | ~3-5s | High-quality final render |
| GPU Live | 800x600 | 30-60 FPS | Real-time, interactive |
| WebGPU | 800x600 | 25-50 FPS | 15-20% slower than native |
Note: Benchmarks are approximate and measured on modern hardware (M1/M2 Mac or RTX 3000+ series GPU). Your results may vary.
Completed:
- Sphere ray tracing
- Direct and indirect lighting calculations
- Triangle meshes and .obj loading
- GPU acceleration with compute shaders
- Shadows and reflections
- Interactive real-time viewer
- WebAssembly/WebGPU support
- BVH acceleration structure for faster ray-mesh
- Progressive rendering with denoising
Planned:
intersection
- Texture mapping (UV coordinates and image textures)
- Additional material types (glass, subsurface scattering)
- Scene file format for easy scene definition
- Camera controls (zoom, pan, dolly)
Built with Rust and powered by:
Made with ❤️ by tchauffi
Star ⭐ this repository if you find it helpful!
