Git Product home page Git Product logo

rpt's Introduction

rpt

Latest Version API Documentation

This is a physically based, CPU-only rendering engine written in Rust. It uses path tracing to generate realistic images of 3D scenes.

Demo renders Demo video

Features

  • Simple declarative API, 100% Safe Rust
  • Supports .OBJ, .MTL, and .STL file formats
  • Uses unbiased path tracing for physically-based light transport
  • Uses a microfacet BSDF model with multiple importance sampling
  • Uses kd-trees to accelerate ray intersections
  • Supports direct light sampling and emissive materials
  • Supports HDRI environment maps
  • Supports depth of field
  • Supports iterative rendering, variance estimation, and firefly reduction
  • Supports physics simulation with numerical integrators and particle systems
  • Uses all CPU cores concurrently, scaling linearly up to 96 cores

Quickstart

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

Library Usage

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();
}

Example output

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!

References

Samples

Dragon Cornell box Pegasus Lego plane Fractal spheres Rustacean Wine glass Spheres

Acknowledgements

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.

rpt's People

Contributors

ekzhang avatar laurelkeys avatar scanhex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpt's Issues

Max bounce termination

Hi! I noticed that the renderer currently terminates tracing the ray based on a max_bounce parameter. This, as far as I am aware, isn't unbiased. Instead, one would generally probabilistically decide to continue or terminate, adjusting the monte carlo estimator accordingly (also called russian roulette). However, I am not sure if there's something else that's accounting for this which still makes this approach unbiased.

Would love to know, and am happy to make a PR changing this!

WASM Support

Awesome crate!! I'd love to make a little demo in a web app, but some of the deps don't compile for WASM.

Is this something you are interested in? I'd be happy to make a PR adding support if so.

Heavy CPU use causing hanging

Hello there.

I'm quite new to Rust but I wanted to use this lib to generate thumbnails for STLs in a neat way.
I have pretty much copy pasted the cylinder example and tried feeding it the paths to the STL, however this causes it to 'hang' and consume a lot of CPU, it also never finishes. Code snippet below.

I'm just wondering if this is the natural state of this library, seeing it is 'cpu' only.

pub fn gen_thumb(path: PathBuf) -> color_eyre::Result<()> {
    use std::fs::File;
    color_eyre::install()?;
    let mut extension = path.clone();
    extension.set_extension("png");
    
    let mut scene = Scene::new();
    scene.add(
        Object::new(load_stl(File::open(path)?)?)
            .material(Material::specular(hex_color(0xB7CA79), 0.1))
    );
        scene.add(
        Object::new(plane(glm::vec3(0.0, 1.0, 0.0), -1.0))
            .material(Material::diffuse(hex_color(0xAAAAAA))),
    );
    scene.add(Light::Ambient(glm::vec3(0.01, 0.01, 0.01)));
    scene.add(Light::Object(
        Object::new(
            sphere()
                .scale(&glm::vec3(2.0, 2.0, 2.0))
                .translate(&glm::vec3(0.0, 20.0, 3.0)),
        )
        .material(Material::light(glm::vec3(1.0, 1.0, 1.0), 160.0)),
    ));
    scene.add(Light::Object(
        Object::new(
            sphere()
                .scale(&glm::vec3(0.05, 0.05, 0.05))
                .translate(&glm::vec3(-1.0, 0.71, 0.0)),
        )
        .material(Material::light(hex_color(0xFFAAAA), 400.0)),
    ));

    let camera = Camera::look_at(
        glm::vec3(-2.5, 4.0, 6.5),
        glm::vec3(0.0, 0.0, 0.0),
        glm::vec3(0.0, 1.0, 0.0),
        std::f64::consts::FRAC_PI_6,
    );
    Renderer::new(&scene, camera)
        .max_bounces(2)
        .num_samples(1)
        .render()
        .save(extension.as_path())?;

    Ok(())
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.