Rust Raytracer is an implementation of a simple raytracer based on "Ray Tracing in One Weekend" by Peter Shirley. Developed to learn Rust from scratch, the project might not be perfectly idiomatic but it produces visually appealing results. Additional features beyond Shirley's course include texture mapping, lighting, parallel rendering, reading scene data from JSON, and rendering a sky texture.
The Rust Raytracer project was created to explore the fundamentals of ray tracing while learning the Rust programming language. It extends the basic implementation provided in Peter Shirley's "Ray Tracing in One Weekend" with several advanced features to enhance rendering capabilities.
Latest output
https://user-images.githubusercontent.com/237355/147687883-4e9ca4fc-7c3b-4adb-85d7-6b08d1bc69f7.mp4
To build and run the raytracer, use the following commands:
$ cargo build --release
Compiling raytracer v0.1.0 (/path/to/rust-raytracer/raytracer)
Finished release [optimized] target(s) in 2.57s
$ ./target/release/raytracer data/test_scene.json out.png
Rendering out.png
Frame time: 2840ms
$ ./target/release/raytracer data/cover_scene.json cover.png
Rendering cover.png
Frame time: 27146ms
cover_alt
lighting-recast-final
Parallel rendering significantly improves performance by utilizing multiple CPU cores.
Rendering anim/frame_000.png
............................................................
Frame time: 21s
Rendering anim/frame_000.png
Frame time: 2573ms
sky_textures
{
"width": 800,
"height": 600,
"samples_per_pixel": 128,
"max_depth": 50,
"sky": {
"texture": "data/beach.jpg"
},
"camera": {
"look_from": { "x": -2.0, "y": 0.5, "z": 1.0 },
"look_at": { "x": 0.0, "y": 0.0, "z": -1.0 },
"vup": { "x": 0.0, "y": 1.0, "z": 0.0 },
"vfov": 50.0,
"aspect": 1.3333333333333333
},
"objects": [
{
"center": { "x": 0.0, "y": 0.0, "z": -1.0 },
"radius": 0.5,
"material": {
"Texture": {
"albedo": [1.0, 1.0, 1.0],
"pixels": "data/earth.jpg",
"width": 2048,
"height": 1024,
"h_offset": 0.75
}
}
}
]
}
To create an animation from rendered frames, use:
ffmpeg -f image2 -framerate 15 -i anim/frame_%03d.png -loop -0 anim.gif
147705264-c6f439df-f61b-4bcf-b5e6-c2c755b35b1c
max_depth_anim
rs_pbrt is a Rust crate implementing the PBRT book's C++ code for physically based rendering.