A principled BSDF pathtracer with an abstracted backend. Perfect for rendering procedural content.

Overview

This is a port of the excellent GLSL_Pathtracer to Rust utilizing an abstracted, trait based backend. Perfect for rendering procedural content.

Spheres

Rust Features

  • Multi threaded using rayon.
  • An abstracted backend via a scene description trait. Implement hit tests, lights and materials for your procedural content.
  • The pathtracer can be compiled to either f32 or f64. See the defines in the libs.rs. Default is f64 for now.

Todo

  • Support of mediums / volumetric objects.
  • Implement a denoiser.
  • Emitters are untested right now.
  • Only spherical analytical lights right now.
  • Document classes for crate.
  • Implement a SDF based example scene.
  • Implement a mesh based example scene. PRs welcome.
  • Enhance the example renderer app with more options.
  • More testing.

How to use

// Create a color buffer
let mut buffer = ColorBuffer::new(800, 600);

// Create a scene and pass it to the path-tracer
let scene = Box::new(AnalyticalScene::new());
let mut pt = Tracer::new(scene);

// Render and accumulate one frame, repeat
pt.render();

You can copy the color buffer into an Vec<u8> by calling buffer.convert_to_u8(frame); or you can access the float pixels directly by accessing buffer.pixels.

Scenes

Scenes contain objects, lights, the background and material definitions.

The scene trait is pretty small right now.

pub trait Scene : Sync + Send {

    fn new() -> Self where Self: Sized;

    /// Background color for the given ray
    fn background(&self, ray: &Ray) -> PTF3;

    /// Closest hit should return the state.hit_dist, state.normal and fill out the state.material as needed
    fn closest_hit(&self, ray: &Ray, state: &mut State, light: &mut LightSampleRec) -> bool;

    /// Used for shadow rays.
    fn any_hit(&self, ray: &Ray, max_dist: PTF) -> bool;

    /// Return the camera for the scene
    fn camera(&self) -> &Box<dyn Camera3D>;

    /// Return the number of lights in the scene
    fn number_of_lights(&self) -> usize;

    /// Return a reference for the light at the given index
    fn light_at(&self, index: usize) -> &AnalyticalLight;
}

The analytical example scene which creates the above screenshot can be found inside the renderer here.

Renderer

The repository contains an example renderer which displays the ongoing rendering process. You can easily run it with cargo run --release. The renderer will be enhanced with additional features soon (write images to disk, display a frame counter etc).

CPU vs GPU: Motivation

I prefer to render SDFs on the CPU. Of course the GPU is faster and there are many great Shadertoy demos, however when the SDF complexity of a scene is user defined and you do not know the OS or GPU of the user, one of these things can happen:

  • Shaders take seconds to compile and depending on the platform can freeze your app while doing so.
  • Shaders can run so slow that they make your app hard to use.
  • In the worst case shaders can crash.

The CPU renders slower but does not need to compile shaders and render tasks can be nicely handled in the background without affecting the overall performance of the app.

You might also like...
Pixel-perfect integer scaling for windowed applications

integer-fullscreen Pixel-perfect integer scaling for windowed applications. Usage Run the program. Move your cursor to a window you would like to get

A simple camera for properly displaying tile-based low resolution pixel perfect 2D games in bevy.
A simple camera for properly displaying tile-based low resolution pixel perfect 2D games in bevy.

Bevy Tiled Camera A simple camera for properly displaying low resolution pixel perfect 2D games in bevy. The camera will adjust the viewport to scale

Generate perfect code headers every time.

Generate perfect code headers every time.

✨ A perfect template for a binary rust project.

Rust Template A project template for Rust, helping to structure your projects blazingly fast ⚡ . Features 🔥 Code-ready for binary projects. Add amazi

Generate perfect Vyper compatible code headers every time.

headers-vy Generate perfect Vyper-compatible code headers every time. Build You need Rust and Cargo installed on your machine. See the installation gu

The frequency-perfect synthesizer for a PC-speaker

🎵 BeeSynth Project The frequency-perfect synthesizer for a PC speaker ✔️ Features Written in Rust 🦀 Support playing MP3, WAV, FLAC, tracker music an

With Dejavu, you can have a perfect memory by capturing and organizing your visual recordings efficiently.

Dejavu The content in README.md is assisted by ChatGPT. Overview Dejavu is an open-source, cross-platform tool designed to help you record and search

A perfect smoother; A discrete time version of spline smoothing for equally spaced data
A perfect smoother; A discrete time version of spline smoothing for equally spaced data

Whittaker Smoother Aka Whittaker-Henderson, Whittaker-Eilers Smoother is known as the perfect smoother. Its a discrete-time version of spline smoothin

Rust implementation of the PTHash perfect hash function for static compile-time generated hash tables

QuickPHF QuickPHF is a Rust implementation of the PTHash minimal perfect hash function algorithm. It consists of two crates: quickphf - runtime code f

Smooth pixel-perfect camera for Bevy

bevy_smooth_pixel_camera A bevy plugin that adds a simple smooth pixel camera. The smoothing is based on this video from aarthificial which explains h

Procedural engine sound generator controlled via GUI or CLI
Procedural engine sound generator controlled via GUI or CLI

enginesound GUI Application used to generate purely synthetic engine sounds with advanced options written in Rust loosely based on this paper Reading

PostgreSQL procedural language handler for Clojure via SCI

pl/sci Status This is very much an experiment and I'm open to feedback on where to take this next. Build Requirements lein GraalVM CE 20.3.0 Java 11 c

Safe Rust --- GraalVM Polyglot bindings using procedural macros

The class macro is the primary way to generate bindings to Java types; it will generate a struct (with generics if specified) that implements Pass and Receive and has all the methods you give stubs for. The methods generated can be used like normal rust methods, however mutability is not enforced. The fully-qualified type name should precede a block containing method and constructor stubs. Java primitives like char, int, and byte are aliased to corresponding Rust types.

Obake is a procedural macro for declaring and maintaining versioned data-structures.

Obake is a procedural macro for declaring and maintaining versioned data-structures. The name 'obake' is taken from the Japanese 'お化け (おばけ)', a class of supernatural beings in Japanese folklore that shapeshift.

todo-or-die provides procedural macros that act as checked reminders.

todo-or-die provides procedural macros that act as checked reminders.

A procedural sky plugin for bevy

bevy_atmosphere A procedural sky plugin for bevy Example use bevy::prelude::*; use bevy_atmosphere::*; fn main() { App::build() .insert_re

Procedural-generation in Rust
Procedural-generation in Rust

Procedural Generation This is a crate for for procedurally generating maps written in Rust. It's very elegant to use and creates nice results, see the

Procedural macros for Floccus

floccus-proc Procedural macros for floccus This crate contains procedural attribute macros (currently only one) used by the floccus. But potentially c

Js-macros - Quickly prototype Rust procedural macros using JavaScript or TypeScript!

js-macros Quickly prototype Rust procedural macros using JavaScript or TypeScript! Have you ever thought "this would be a great use case for a procedu

Owner
Markus Moenig
Creator of Open Source graphic applications and games using Rust, Swift and Metal. Enjoying life in Thailand.
Markus Moenig
Simple procedural macros `tnconst![...]`, `pconst![...]`, `nconst![...]` and `uconst![...]` that returns the type level integer from `typenum` crate.

typenum-consts Procedural macros that take a literal integer (or the result of an evaluation of simple mathematical expressions or an environment vari

Jim Chng 3 Mar 30, 2024
Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files.

Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files. Mozilla's MDN has a good reference for CSS selector syntax.

Michael Maclean 6.3k Jan 3, 2023
A pure Rust PLONK implementation using arkworks as a backend.

PLONK This is a pure Rust implementation of the PLONK zk proving system Usage use ark_plonk::prelude::*; use ark_ec::bls12::Bls12; use rand_core::OsRn

rust-zkp 201 Dec 31, 2022
A Zincati lock backend for stateful workloads.

This repository is deprecated. We realized CoreOS is probably not a good fit for us. The repository will be kept up on the off chance that this is use

Open Computing Facility 6 Dec 7, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
A pathtracer written in rust - runs in the web and includes an editor

Webtracer A pathtracer written in rust - runs in the web and includes an editor Rendering is parallelized and utilizes all cpu cores You can easily ed

Shapur 5 Oct 7, 2022
Let Tauri's transparent background rendering window be stacked on Bevy's rendering window in real time to run the game with native-level performance!

Native Bevy with Tauri HUD DEMO 将 Tauri 的透明背景渲染窗口实时叠在 Bevy 的渲染窗口上,以使用原生级别性能运行游戏! Let Tauri's transparent background rendering window be stacked on Bev

伊欧 3 Mar 25, 2024
A render-backend independant egui backend for sdl2

A Sdl2 + Egui Backend An egui backend for sdl2 unbound to any renderer-backend. You can include it like so: [dependencies] egui_sdl2_platform = "0.1.0

null 4 Dec 16, 2022
Pixel-Perfect, 2D Renderer for Bevy that Seamlessly Targets Desktop and Web

bevy_retro ( Screenshot of Bounty Bros. game made with Bevy Retro and Skip'n Go ) Bevy Retro is a 2D, pixel-perfect renderer for Bevy that can target

Katharos Technology 224 Dec 23, 2022
Pitch-perfect copy of map generation algorithm from Slay the Spire

sts_map_oracle Pitch-perfect copy of map generation algorithm from Slay the Spire Usage Prints out map layouts in console for given seed: sts_map_orac

Rusty 0ne 12 Dec 20, 2022