tracing icon indicating copy to clipboard operation
tracing copied to clipboard

A simple physically-based path tracer

A simple physically-based path tracer

This is a physically-based path tracer I wrote from scratch in Rust to better understand how modern renderers work. Below are some renders it produced.

testball

testball

testball

testball

Rendering actually touches many domains (geometry, image reconstruction, spatial data structures, optics, …) and learning all of them was fun, challenging and rewarding. The codebase is much simpler than feature-rich reference implementations such as pbrt or Mitsuba, but poorly documented.

Features

  • Full physically based global illumination using unbiased unidirectional pathtracing with multiple importance sampling (BSDF and direct light sampling)
  • Support meshes composed millions of triangles (the dragon above has more than 800k triangles) loaded from OBJ files and some geometric primitives (sphere, parallelogram, …)
  • Area lights (parallelogram and sphere shaped) and Image Based Lighting (see the dragon above)
  • Several physically based materials:
  • Bitmap textures (loaded from common image formats) that can be used to describe material albedo but also roughness (when applicable)
  • Two-levels acceleration structure system based on Bounded Volume Hierarchies constructed with the Surface Area Heuristic
  • Depth of Field effect
  • Fully parallelized rendering
  • Progressive rendering with live preview in a SDL window (can be disabled)

Usage

As this project is not meant for real-use, the interface is not very polished. There are two ways to describe a scene to render.

  • Describe a scene in Rust with the provided library. An example is given in examples/cornell.rs and can be executed with:

    cargo run --release --example=cornell
    
  • Use the Tungsten file format, although only a very limited subset is supported. An example of scene can be found in scenes/material-testball and rendered with:

    cargo run --release --bin=render_tungsten -- scenes/material-testball/scene.json
    

The current render is saved in /tmp/image.ppm when exiting the preview.

TODO

  • Bump mapping
  • Adaptive sampling

Credits

The bathroom, staircase and material test ball scenes are courtesy of Benedikt Bitterli.