Skip to content
Jan Walter edited this page Aug 18, 2017 · 31 revisions

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

http://www.pbrt.org

Current Rust documentation:

https://www.janwalter.org/doc/rust/pbrt/index.html

Current Status

The library is kept in a single file (called src/lib.rs), an example directory contains several example files using the library.

Warning: If you want to compile the pest_test executable you need to download and compile with Rust nightly:

rustup install nightly
rustup default nightly

You can compile with Rust stable if you remove the pest_test.rs file before compilation:

rm examples/pest_test.rs
rustup default stable
cargo test --release

API

One executable does use the library and generates a test scene purely with API calls:

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

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

Checker

Use procedural texture

Image

Use image texture

No Texture

use no texture

Matte

Only matte materials

Parser

The second executable can parse a scene description via the pest crate and has to be compiled with Rust nightly:

rustup install nightly
rustup default nightly
cargo test --release
./target/release/examples/pest_test -h
Usage: ./target/release/examples/pest_test [options]

Options:
    -h, --help          print this help menu
    -i FILE             parse an input file
    -v, --version       print version number

Spheres

You can render the same test scene as above (using a texture file on the ground) like this:

./target/release/examples/pest_test -i assets/scenes/spheres-differentials-texfilt.pbrt

Teapot

The scene can be rendered by simply pointing to another provided input file:

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

The resulting image is almost identical to the C++ version of PBRT:

Teapot scene rendered via Rust version of PBRT

Cornell Box

The scene will later be used for global illumination, but right now it renders only with direct lighting:

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

The resulting image matches the C++ counterpart a hundred percent:

Cornell Box scene rendered via Rust version of PBRT

imf_diff -d -f pbrt.png pbrt_cpp.png
pbrt.png pbrt_cpp.png: no differences.
== "pbrt.png" and "pbrt_cpp.png" are identical

Without releasing another version there was a task to implement ambient occlusion (AO), and here is the resulting image:

Cornell Box scene rendered via Rust using AO

You have to change the following line to use the AOIntegrator:

Integrator "ambientocclusion"

Example .pbrt File

The forth provided scene can be parsed but does not render (yet):

> ./target/release/examples/pest_test -i assets/scenes/example.pbrt
...
do something with created tokens ...
...
TODO: UVMapping2D
...
TODO: CreateDiskShape
...
WorldEnd
done.

The scene comes from here:

http://www.pbrt.org/fileformat-v3.html#example

Clone this wiki locally