Path Tracing, Ambient Occlusion, and a Parser

24 Aug 2017

Release Notes

Rust crate to implement at least parts of the PBRT book's C++ code:

Current Rust documentation:


Let's first show the latest image:

Cornell Box scene rendered via Rust version of PBRT using path
tracing (low settings)

This was rendered using path tracing. Since my last post a lot of things changed. First of all I started implementing a parser using a crate called pest. The parser isn't finished yet, but I provide some sample scenes which can be used and should render. The image above was for example rendered by the following command line ($ is the command prompt):

$ ./target/release/examples/pest_test -i assets/scenes/cornell_box.pbrt

Cloning the Repository

To compile the executable mentioned above you first need to clone the repository:

$ git clone


The easiest way to install Rust is rustup:

$ curl -sSf | sh

I first started using some Rust features which require Rust nightly when I started working on the parser, but currently even the library (API) needs it:

$ rustup install nightly
$ rustup default nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.20.0-nightly


After switching to the nightly version you should be able to compile:

$ cargo test --release
   Compiling pest v0.4.1
   Compiling image v0.15.0
    Finished release [optimized] target(s) in 113.58 secs
     Running target/release/deps/pbrt-e363c28050f255bc

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests pbrt

running 16 tests
test src/ -  (line 166) ... ok
test src/ -  (line 24) ... ok
test src/ -  (line 204) ... ok
test src/ -  (line 112) ... ok
test src/ -  (line 241) ... ok
test src/ -  (line 277) ... ok
test src/ -  (line 301) ... ok
test src/ -  (line 319) ... ok
test src/ -  (line 373) ... ok
test src/ -  (line 344) ... ok
test src/ -  (line 412) ... ok
test src/ -  (line 462) ... ok
test src/ -  (line 53) ... ok
test src/ -  (line 551) ... ok
test src/ -  (line 596) ... ok
test src/ -  (line 84) ... ok

test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out


Now you are ready to render:

$ ./target/release/examples/pest_test -i assets/scenes/cornell_box.pbrt
Rendering finished
Converting image to RGB and computing final weighted pixel values
Writing image "pbrt.png" with bounds Bounds2 { p_min: Point2 { x: 0, y: 0 }, p_max: Point2 { x: 500, y: 500 } }

This should take only a couple of seconds. Don't worry if your resulting image will look a lot more noisy. To render the exact same image as above you have to tweak some settings in the scene descrition file (cornell_box.pbrt):

Sampler "lowdiscrepancy" "integer pixelsamples" [512]
PixelFilter "gaussian" "float xwidth" [2.000000 ] "float ywidth" [2.000000 ]
Integrator "path"

Direct Lighting

To render without global illumination you can use the direct lighting integrator:

Integrator "directlighting" "integer maxdepth" [10]

Don't forget to use lower pixelsamples settings (maybe 8).

Cornell Box scene rendered with direct lighting

Ambient Occlusion

To render with ambient occlusion switch (again) the integrator:

Integrator "ambientocclusion"

Cornell Box scene rendered with ambient occlusion

Other Scenes

There are a couple of other scenes which can be rendered from the command line by parsing a scene description file, e.g. a teapot illuminated by an area light:

$ ./target/release/examples/pest_test -i assets/scenes/teapot-area-light.pbrt

Teapot scene rendered with direct·lighting

Variations of the Same Scene

From the time where I didn't have a parser there exists an executable which uses only the API (see also Wiki):

$ ./target/release/examples/pbrt_spheres_differentials_texfilt --help
Usage: ./target/release/examples/pbrt_spheres_differentials_texfilt [options]

    -h, --help          print this help menu
    -c, --checker       use procedural texture
    -i, --image         use image texture
    -n, --none          use no texture
    -m, --matte         use only matte materials
    -v, --version       print version number


Using a
procedural pattern on the floor.


Using a
image file as texture on the floor.

No Texture



Matte only


If you want to contribute to this project contact me via the email provided on the imprint page.