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