Skip to main content

euv_engine/raytracing/
struct.rs

1use super::*;
2
3/// A 3D ray carrying the parameters needed for traversal and depth tracking.
4#[derive(Clone, Data, Debug, PartialEq)]
5pub struct Ray {
6    /// The world-space origin of the ray.
7    #[get(type(copy))]
8    pub(crate) origin: Vector3D,
9    /// The unit direction of the ray.
10    #[get(type(copy))]
11    pub(crate) direction: Vector3D,
12    /// The minimum acceptable `t` value for valid intersections.
13    #[get(type(copy))]
14    pub(crate) t_min: f64,
15    /// The maximum `t` value before the ray escapes the scene.
16    #[get(type(copy))]
17    pub(crate) t_max: f64,
18    /// The current recursion depth (used to terminate recursive bounces).
19    #[get(type(copy))]
20    pub(crate) depth: u32,
21}
22
23/// The result of a ray-object intersection.
24#[derive(Clone, Data, Debug, PartialEq)]
25pub struct Hit {
26    /// The ray parameter at the hit point.
27    #[get(type(copy))]
28    pub(crate) t: f64,
29    /// The world-space hit position.
30    #[get(type(copy))]
31    pub(crate) position: Vector3D,
32    /// The outward unit normal at the hit point.
33    #[get(type(copy))]
34    pub(crate) normal: Vector3D,
35    /// The material of the hit surface.
36    pub(crate) material: Material,
37}
38
39/// A ray-traceable geometric surface with an attached material.
40#[derive(Clone, Data, Debug, PartialEq)]
41pub struct Occluder {
42    /// The geometric shape represented by this occluder.
43    #[get(type(copy))]
44    pub(crate) kind: OccluderKind,
45    /// For spheres: the center. For AABBs: the minimum corner. Unused by
46    /// triangles, whose vertices live in `vertices`.
47    #[get(type(copy))]
48    pub(crate) center: Vector3D,
49    /// For spheres: `.x` is the radius. For AABBs: the maximum corner.
50    /// Unused by triangles, whose vertices live in `vertices`.
51    #[get(type(copy))]
52    pub(crate) extent: Vector3D,
53    /// For triangles: the three corners in winding order. Unused by spheres
54    /// and AABBs, which are fully described by `center` and `extent`.
55    #[get(type(copy))]
56    pub(crate) vertices: [Vector3D; 3],
57    /// The surface material.
58    pub(crate) material: Material,
59}
60
61/// An owned ray-tracing scene with precomputed shadow data.
62///
63/// `RayTraceScene` bundles the occluder list together with the
64/// `(center, radius)` shadow bounding spheres consumed by
65/// [`soft_shadow_factor`], computing them exactly once at construction.
66/// Tracing through [`RayTraceScene::trace`] performs no heap allocation
67/// per ray or per bounce, making the scene the single canonical entry
68/// point for tracing many rays against a static scene.
69#[derive(Clone, Data, Debug, PartialEq)]
70pub struct RayTraceScene {
71    /// All occluding surfaces in the scene.
72    #[get_mut(skip)]
73    #[set(skip)]
74    pub(crate) occluders: Vec<Occluder>,
75    /// Precomputed `(center, radius)` shadow bounding spheres, one per
76    /// occluder, in the same order as `occluders`.
77    #[get_mut(skip)]
78    #[set(skip)]
79    pub(crate) shadow_points: Vec<(Vector3D, f64)>,
80}