MCPcopy Index your code
hub / github.com/ekzhang/rpt

github.com/ekzhang/rpt @v0.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.1 ↗ · + Follow
175 symbols 521 edges 40 files 70 documented · 40%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Extension points exported contracts — how you extend this code

Bounded (Interface)
A geometric shape with a bounding box (needed for kd-tree intersections) [8 implementers]
src/kdtree.rs
Shape (Interface)
Represents a physical shape, which can be hit by a ray to find intersections [9 implementers]
src/shape.rs
ParticleSystem (Interface)
A trait that represents a system formulating some physical laws [3 implementers]
src/ode/particle_system.rs
SceneAdd (Interface)
Trait that allows adding an object or light to a scene [2 implementers]
src/scene.rs
Transformable (Interface)
An object that can be transformed [1 implementers]
src/shape.rs

Core symbols most depended-on inside this repo

add
called by 88
src/scene.rs
material
called by 64
src/object.rs
hex_color
called by 59
src/color.rs
scale
called by 38
src/shape.rs
translate
called by 34
src/shape.rs
sphere
called by 24
src/shape.rs
width
called by 19
src/renderer.rs
height
called by 19
src/renderer.rs

Shape

Method 84
Function 61
Class 21
Interface 5
Enum 4

Languages

Rust100%

Modules by API surface

src/shape.rs24 symbols
src/renderer.rs15 symbols
src/kdtree.rs14 symbols
src/material.rs11 symbols
src/io.rs10 symbols
src/buffer.rs9 symbols
src/shape/monomial_surface.rs7 symbols
src/ode/particle_system.rs7 symbols
src/environment.rs6 symbols
src/shape/mesh.rs5 symbols
src/camera.rs5 symbols
src/shape/sphere.rs4 symbols

For agents

$ claude mcp add rpt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact