A cross-platform demo GPU ray tracer built with Rust and WebGPU, demonstrating modern GPU programming techniques. Runs natively on Windows, macOS, and Linux, as well as in web browsers from the same codebase.
This is a real-time GPU ray tracer that:
- Renders 3D scenes loaded from glTF (.glb) files (tested with Blender exported files)
- Runs the same Rust codebase natively (desktop) and on the web (via WebAssembly)
- Uses compute shaders for ray-triangle intersection (Möller-Trumbore algorithm)
- Handles first-person camera controls with keyboard and mouse input
- Demonstrates core WebGPU (wgpu v27) concepts: bind groups, compute/vertex/fragment pipelines, WGSL compute/vertex/fragment shaders, storage textures, etc.
Current Status: This is a basic ray tracer skeleton (~1300 lines of code in total). It traces primary rays only and lacks features like recursive path tracing or acceleration structures (BVH).
-
Install Rust
-
For web builds, install wasm-pack:
cargo install wasm-pack
-
For web hosting on localhost, use Python's built-in server or install simple-http-server:
cargo install simple-http-server
git clone https://github.com/0dpe/path_tracer.git
cd path_tracer
cargo run --releaseControls: Left click the window, then use WASD + Left Shift/Space to move, mouse to look around. Press Esc or click again to release cursor.
git clone https://github.com/0dpe/path_tracer.git
cd path_tracer
wasm-pack build --target web
# serve the folder
simple-http-server
# Or: python -m http.server 8000Open Chrome at http://localhost:8000 and click on index.html. Same controls as native.
Note
Requires a browser with WebGPU support (Chrome stable, Safari/Firefox with flags enabled as of 2025).
path_tracer/
├── assets/ # .glb scene files
├── pkg/ # Auto-generated by wasm-pack
├── src/
│ ├── render/ # WebGPU setup, shaders, scene loading
│ ├── lib.rs # Window management and event loop
│ └── main.rs # Native entry point
├── Cargo.toml # Dependencies and wgpu version
└── index.html # Webpage
GPU programming offers massive parallelism for graphics and compute workloads, but has historically been fragmented across incompatible APIs:
- OpenGL: Relatively old, high-level and opaque
- DirectX: Windows-only
- Metal: Apple platforms only
- Vulkan: Verbose, complex to learn
- CUDA & OpenCL: Compute-focused, vendor-specific or limited adoption
Unlike CPU code that runs anywhere with minimal changes, GPU code has traditionally required developers to choose between portability, modern features, and accessibility.
WebGPU solves this. It's a modern, cross-platform GPU API that provides a single interface across all major platforms and browsers. WebGPU maps efficiently to DirectX 12, Metal, and Vulkan without sacrificing performance. The W3C WebGPU spec reached a Candidate Recommendation Draft in 2025.
This project demonstrates WebGPU capabilities using wgpu (the Rust implementation) and serves as a practical demo for modern GPU programming.