Skip to content

GPU accelerated path tracer written entirely in Rust

License

Notifications You must be signed in to change notification settings

pema99/rust-path-tracer

Repository files navigation

Yet another path tracer

Yet another GPU accelerated toy path tracer, but everything is written in Rust (:rocket:) - both the GPU and CPU code. Uses rust-gpu to transpile Rust (:rocket:) code to SPIR-V, and then uses wgpu to execute that SPIR-V.

Features

  • Simple GPU accelerated path tracing.
  • Supports PBR materials with roughness/metallic workflow. These can be set on a per-mesh basis.
  • Supports texture mapping. Can load albedo, normal, roughness and metallic maps from scene file.
  • Ray intersections are made fast using a BVH built in a binned manner using the surface area heuristic.
  • Convergence rate is improved by the use of a low-discrepancy sequence in place of uniform random sampling.
  • Basic next event estimation (direct light sampling).
  • Uses assimp for scene loading, so can load many scene and model file formats, such as glTF, FBX, obj, etc.
  • Uses a nice procedural atmospheric skybox (thanks @nyrox). Alternatively, can load HDR images to use as the skybox.
  • Cross platform. Tested on Windows 10 and Arch Linux.
  • All the GPU code can be run on the CPU via a dropdown in the UI. Mostly useful for debugging.

How to build and run

# builds without denoising support
cargo run

The path tracer optionally supports denoising via OpenImageDenoise, via feature flag oidn. To use this feature, first install OpenImageDenoise 1.4.3 and ensure that the OIDN_DIR environment variable points to your install location.

# with denoising (requires OIDN to be installed and available on PATH)
export OIDN_DIR <path_to_oidn_install>
cargo run -F oidn

Once built and launched, to start rendering, simply drag any compatible scene file onto the window, or use the file picker. Holding right click and using WASD will let you move the camera.

I've only tested using Vulkan. If wgpu for whatever reason defaults to a different backend on your system, you can fix this by setting the WGPU_BACKEND environment variable to "vulkan".

GPU kernel code is in kernels/, code shared between GPU and CPU is in shared_structs/, pure CPU code is in src/.

Pretty pictures

image image image image image image

About

GPU accelerated path tracer written entirely in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published