solstrale/lib.rs
1#![warn(missing_docs)]
2//! A multithreaded Monte Carlo path tracing library, that as such has features like:
3//! * Global illumination
4//! * Caustics
5//! * Reflection
6//! * Refraction
7//! * Soft shadows
8//!
9//! Additionally, the library has:
10//! * Loading of obj models with included materials
11//! * Multithreaded Bvh creation to greatly speed up rendering
12//! * Post-processing of rendered images by:
13//! * [Open Image Denoise](https://www.openimagedenoise.org/)
14//! * Bloom filter
15//! * Bump mapping
16//! * Light attenuation
17//!
18//! ## Example:
19//! ```rust
20//! # use std::sync::mpsc::channel;
21//! # use std::thread;
22//! # use image::RgbImage;
23//! # use solstrale::camera::CameraConfig;
24//! # use solstrale::geo::vec3::Vec3;
25//! # use solstrale::hittable::{Bvh, Sphere, Hittable};
26//! # use solstrale::material::{DiffuseLight, Lambertian};
27//! # use solstrale::material::texture::SolidColor;
28//! # use solstrale::ray_trace;
29//! # use solstrale::renderer::{RenderConfig, Scene};
30//! # use solstrale::renderer::shader::PathTracingShader;
31//! let camera = CameraConfig {
32//! vertical_fov_degrees: 20.,
33//! aperture_size: 0.1,
34//! look_from: Vec3::new(0., 0., 4.),
35//! look_at: Vec3::new(0., 0., 0.),
36//! up: Vec3::new(0., 1., 0.),
37//! };
38//! let mut world = Vec::new();
39//! let yellow = Lambertian::new(SolidColor::new(1., 1., 0.), None);
40//! let light = DiffuseLight::new(10., 10., 10., None);
41//! world.push(Sphere::new(Vec3::new(0., 0., 0.), 0.5, yellow));
42//!
43//! let scene = Scene {
44//! world: Bvh::new(world),
45//! camera,
46//! background_color: Vec3::new(0.2, 0.3, 0.5),
47//! render_config: RenderConfig::default(),
48//! };
49//!
50//! let (output_sender, output_receiver) = channel();
51//! let (_, abort_receiver) = channel();
52//!
53//! thread::spawn(move || {
54//! ray_trace(scene, &output_sender, &abort_receiver).unwrap();
55//! });
56//!
57//! for render_output in output_receiver {
58//! let _image = render_output.render_image;
59//! }
60//! ```
61//!
62//! ## Example output
63//! 
64//! 
65//! 
66//! 
67
68//! ## Credits
69//! The ray tracing is inspired by the excellent [Ray Tracing in One Weekend Book Series](https://github.com/RayTracing/raytracing.github.io) by Peter Shirley
70
71use crate::renderer::{RenderProgress, Renderer, Scene};
72use std::error::Error;
73use std::sync::mpsc::{Receiver, Sender};
74
75pub mod camera;
76pub mod geo;
77pub mod hittable;
78pub mod loader;
79pub mod material;
80pub mod pdf;
81pub mod post;
82pub mod random;
83pub mod renderer;
84pub mod util;
85
86/// Executes the ray tracing with the given [`Scene`] and reports [`RenderProgress`] on
87/// the output [`Sender`]. Listens to abort [`Receiver`] for aborting a started ray trace operation
88///
89/// # Arguments
90/// * `scene` - A scene describing how, and what should be rendered
91/// * `output` - Channel where render progress will be sent
92/// * `abort` - Channel to send abort signals to the renderer
93pub fn ray_trace<'a>(
94 scene: Scene,
95 output: &'a Sender<RenderProgress>,
96 abort: &'a Receiver<bool>,
97) -> Result<(), Box<dyn Error>> {
98 Renderer::new(scene)?.render(output, abort)
99}