[][src]Crate rustic_zen

Photon Garden Raytracer Impementation.

Rustic Zen renders artworks from a scene definition by simulating individual photons and tracing their path as they bounce through a 2D. space.

Photons are generated by Lights and interact with Objects. Each interaction results in either the photon being absorbed, or being allowed to continue with a new direction, based on the rules defined by the Object's Material.

Example usage:

extern crate rustic_zen;
use rustic_zen::prelude::*;

fn main() {
    // Set up constants.
    let width: f64 = 3440.0;
    let height: f64 = 1440.0;
    let rays = 100_000;
    // This would be better but these doctests have to run in reasonable time
    // let rays = ((width * height).round() / 2.0) as usize;

    // Build a basic Material
    let m = Box::new(HQZLegacy::new(0.3, 0.3, 0.3));

    // Build a basic Object
    let o = Object::Line {
        x0: Sample::Constant(0.0),
        y0: Sample::Constant(height*0.75),
        dx: Sample::Constant(width),
        dy: Sample::Constant(0.0),
        material: m,

    // Build a basic Light
    let l = Light{
        power: Sample::Constant(1.0),
        x: Sample::Constant(width/2.0),
        y: Sample::Constant(height/2.0),
        polar_angle: Sample::Constant(0.0),
        polar_distance: Sample::Constant(0.0),
        ray_angle: Sample::Range(360.0, 0.0),
        wavelength: Sample::Blackbody(4500.0),

    // We also need a viewport
    let viewport = Rect::from_points(&Point{x: 0.0,y: 0.0},&Point{x: width,y: height});

    // Construct a renderer object and add the light and object to it.
    let r = Renderer::new(width as usize, height as usize, viewport).with_object(o).with_light(l);
    // Render Image
    println!("Tracing Rays");
    let image = r.render(rays);

    // Output the Image as a Vec<u8>
    let data = image.to_rgb8(0.7, 1.2);
    // Do Export to a PNG or whatever you want here.



This prelude contains everything to quickstart using Rustic Zen.



Reference / Legacy implementation of Material trait.


Represents an image while ray rendering is happening


Data only struct which defines a Light Source


Holds scene Configuration and logic



Holds a definition of an object


Samples a stochastically sampled value, which may be:



Shader Trait