• Stars
    star
    410
  • Rank 105,468 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A physically-based path tracer

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.

More Repositories

1

bore

๐Ÿ•ณ bore is a simple CLI tool for making tunnels to localhost
Rust
7,500
star
2

sshx

Fast, collaborative live terminal sharing over the web
Rust
4,118
star
3

rustpad

Efficient and minimal collaborative code editor, self-hosted, no database required
Rust
3,144
star
4

graphics-workshop

Learn computer graphics by writing GPU shaders!
GLSL
1,999
star
5

percival

๐Ÿ“ Web-based, reactive Datalog notebooks for data analysis and visualization
Rust
595
star
6

composing.studio

Collaborative music composition for everyone.
TypeScript
524
star
7

setwithfriends

๐ŸŽฎ A frictionless multiplayer web app that lets you play Set with friends
JavaScript
523
star
8

crepe

Datalog compiler embedded in Rust as a procedural macro
Rust
420
star
9

inline-sql

๐Ÿช„ Inline SQL in any Python program
Python
407
star
10

fastseg

๐Ÿ“ธ PyTorch implementation of MobileNetV3 for real-time semantic segmentation, with pretrained weights & state-of-the-art performance
Python
334
star
11

classes.wtf

A course catalog with extremely fast full-text search
Go
294
star
12

redis-rope

๐Ÿชข A fast native data type for manipulating large strings in Redis
Zig
110
star
13

ukanren-rs

Rust implementation of ยตKanren, a featherweight relational programming language.
Rust
104
star
14

rushlight

Real-time collaborative code editing on your own infrastructure
TypeScript
95
star
15

dispict

Design a growing artistic exhibit of your own making, with semantic search powered by OpenAI CLIP
Svelte
62
star
16

library

Advanced algorithm and data structure library in C++
C++
55
star
17

char-rnn-keras

TensorFlow implementation of multi-layer recurrent neural networks for training and sampling from texts
Python
42
star
18

harmony

๐ŸŽถ Generate four-part harmony following idiomatic voice-leading procedures with DP!
Python
42
star
19

ekzhang.github.io

Source code for my personal website
Svelte
27
star
20

wkspace

Competitive programming workspace in the cloud, with support for running and testing code
JavaScript
24
star
21

vae-cnn-mnist

Conditional variational autoencoder applied to EMNIST + an interactive demo to explore the latent space.
Jupyter Notebook
22
star
22

game-of-life

Conway's Game of Life simulator running in the browser, based on the HashLife algorithm (quadtrees + memoization)
Vue
21
star
23

aoc23-alpha

Advent of Code 2023 in 25 interesting language specimens, A-Z
Erlang
20
star
24

ekzhang.sty

My personal LaTeX template, with sensible formatting and commands
TeX
15
star
25

aoc21-alpha

Advent of Code 2021 in 25 different languages, alphabet soup edition
Crystal
13
star
26

sketching

Geometry processing for real-time pencil sketching
JavaScript
10
star
27

langevin-music

Noise-conditional score networks for music composition by annealed Langevin dynamics
Python
8
star
28

music-gen

Generate and play music with a recurrent neural network running in the browser!
JavaScript
7
star
29

cs262

Solutions to introductory distributed computing exercises
Rust
6
star
30

webgl-julia-viewer

Real-time Julia Set renderer right in your browser, accelerated with WebGL
TypeScript
6
star
31

market-game

Webapp for running estimation markets
JavaScript
6
star
32

warp-pastebin

Pastebin demo app, powered by warp
Rust
5
star
33

hydroelastics

Efficient contact dynamics simulation using a hydroelastic pressure field model
Julia
5
star
34

triangulate

Fast polygon triangulation in C++, compiled to WebAssembly with Emscripten
C++
4
star
35

julia-fractal

A multithreaded Julia fractal image plotter in C++.
C++
4
star
36

archax

Experiments in multi-architecture parallelism for deep learning with JAX
Python
3
star
37

ekzlib

Source code for the ekzlib website
TypeScript
2
star
38

gravity

JS canvas universal gravity simulator
JavaScript
2
star
39

gha-cross-rs

Fast Rust cross-compilation for every platform in GitHub Actions
Rust
2
star
40

zola-blog-starter

HTML
2
star
41

julia-viewer

Java
1
star
42

chess-aops

Holds code for chess in the AoPS Classroom
JavaScript
1
star
43

inflatable

Code for the paper "Limit Densities of Patterns in Permutation Inflations"
Python
1
star
44

homebrew-bore

Deprecated in favor of official Homebrew Core formula for bore
Ruby
1
star
45

super-tictactoe

Super Tic-Tac-Toe: web interface and Monte Carlo tree search (MCTS) algorithm
JavaScript
1
star
46

warp-react-template

Warp + React + ๐Ÿณ
JavaScript
1
star
47

js-games

Collection of browser-based games for demo purposes, all <200 lines of code
JavaScript
1
star