Crates.io | rpt |
lib.rs | rpt |
version | 0.2.1 |
source | src |
created_at | 2020-11-29 05:06:20.64657 |
updated_at | 2021-02-26 23:48:45.864817 |
description | Physically-based path tracing renderer written in Rust |
homepage | |
repository | https://github.com/ekzhang/rpt |
max_upload_size | |
id | 317660 |
size | 11,583,054 |
This is a physically based, CPU-only rendering engine written in Rust. It uses path tracing to generate realistic images of 3D scenes.
First, clone the repository. The library containing path tracing code is located inside src/
. Example code and scenes are located in examples/
. To compile and run examples/basic.rs
, use the command:
cargo run --example basic
To run tests, use:
cargo test
To use rpt
as a library, add the following to your Cargo.toml
:
[dependencies]
rpt = "0.2"
Here's a simple scene that demonstrates the basics of the API.
use rpt::*;
fn main() {
let mut scene = Scene::new();
scene.add(Object::new(sphere())); // default red material
scene.add(
Object::new(plane(glm::vec3(0.0, 1.0, 0.0), -1.0))
.material(Material::diffuse(hex_color(0xAAAAAA))),
);
scene.add(Light::Object(
Object::new(
sphere()
.scale(&glm::vec3(2.0, 2.0, 2.0))
.translate(&glm::vec3(0.0, 12.0, 0.0)),
)
.material(Material::light(hex_color(0xFFFFFF), 40.0)),
));
let camera = Camera::look_at(
glm::vec3(-2.5, 4.0, 6.5),
glm::vec3(0.0, -0.25, 0.0),
glm::vec3(0.0, 1.0, 0.0),
std::f64::consts::FRAC_PI_4,
);
Renderer::new(&scene, camera)
.width(960)
.height(540)
.max_bounces(2)
.num_samples(100)
.render()
.save("output.png")
.unwrap();
}
This code can also be found in examples/sphere.rs
. Note that the shadow is correctly tinted red due to global illumination. See the detailed API documentation for information about all of the features, and feel free to learn from the other examples!
This project was built by Eric Zhang and Alexander Morozov. We'd like to thank Justin Solomon, Yuanming Hu, Lingxiao Li, and Dmitriy Smirnov for teaching an excellent computer graphics class at MIT.
Some of the examples use free 3D models and image assets available on the Internet. Links are provided in comments in the source code, where used.