lux-aurumque 0.3.1

A transient path tracer in Rust: light propagating at finite speed, rendered frame by picosecond.
Documentation
//! Ray primitive.
//!
//! A ray is an origin plus a direction, parametrized by `t >= 0`.
//! In transient rendering we *also* care about the cumulative optical path
//! length the ray has accumulated so far — this is what gives every photon
//! contribution a definite arrival time at the sensor.

use crate::vec3::Vec3;

/// A ray with cumulative optical path length. The path length is what
/// makes this a *transient* ray rather than a steady-state one — it
/// carries enough state for the time-binned framebuffer to credit each
/// terminal hit to the correct time bin.
#[derive(Clone, Copy, Debug)]
pub struct Ray {
    /// World-space origin.
    pub origin: Vec3,
    /// Unit direction. The constructor normalises whatever it's given.
    pub dir: Vec3,
    /// Optical path length already traveled BEFORE this ray segment starts.
    /// In vacuum this equals geometric distance; in a medium of refractive
    /// index n, it would be n * geometric distance. We assume vacuum.
    pub path_length: f32,
}

impl Ray {
    /// Construct a ray. `dir` is normalised internally; callers may
    /// pass non-unit vectors.
    #[inline]
    pub fn new(origin: Vec3, dir: Vec3, path_length: f32) -> Self {
        Self { origin, dir: dir.normalize(), path_length }
    }

    /// Position along the ray at parameter `t`.
    #[inline]
    pub fn at(&self, t: f32) -> Vec3 {
        self.origin + t * self.dir
    }
}