solstrale 0.2.0

A Path tracing library
Documentation

license CI Crates.io docs.rs

Solstrale

A WGPU-based GPU Monte Carlo path tracing library, with features like:

Core Engine

  • Global illumination
  • Caustics
  • Reflection
  • Refraction
  • Soft shadows
  • Bump mapping
  • Light attenuation

Performance & Loading

  • Loading of obj models with included materials
  • Multithreaded BVH creation using Rayon to greatly speed up rendering

Post-Processing

Custom GPU-accelerated filters implemented as compute shaders via WGPU:

  • Bloom filter
  • Saturation filter

Installation

To build the library, ensure you have Rust installed and run:

cargo build --release

Usage

Running Tests

To run the project's test suite:

cargo test

Library Example

Add solstrale to your Cargo.toml. Below is a basic example of how to set up a scene and start rendering:

use std::sync::mpsc::channel;
use std::thread;
use solstrale::camera::CameraConfig;
use solstrale::geo::vec3::Vec3;
use solstrale::hittable::{Bvh, Sphere};
use solstrale::material::Lambertian;
use solstrale::material::texture::SolidColor;
use solstrale::ray_trace;
use solstrale::renderer::{RenderConfig, Scene};
use solstrale::util::wgpu_util::get_wgpu_device_and_queue;

fn main() {
    let (device, queue) = get_wgpu_device_and_queue();

    let scene = Scene {
        world: Bvh::new(vec![
            Sphere::new(
                Vec3::new(0., 0., 0.), 
                0.5, 
                Lambertian::new(SolidColor::new(1., 1., 0.).into(), None).into()
            ).into()
        ]).into(),
        camera: CameraConfig::default(),
        background_color: Vec3::new(0.2, 0.3, 0.5),
        render_config: RenderConfig::default(),
    };

    let (output_sender, output_receiver) = channel();
    let (_, camera_config_receiver) = channel();
    let (_, abort_receiver) = channel();

    thread::spawn(move || {
        ray_trace(scene, &output_sender, &camera_config_receiver, &abort_receiver, &device, &queue, false).unwrap();
    });

    for render_output in output_receiver {
        // Handle render progress and output buffer
        let _progress = render_output.progress;
    }
}

Example output

bedroom2 conference happy sponza-bump2

Credits

The ray tracing is inspired by the excellent Ray Tracing in One Weekend Book Series by Peter Shirley