Skip to main content

euv_engine/raytracing/pipeline/data/
struct.rs

1use super::*;
2
3/// Ray-tracing quality settings shared by the CPU reference renderer and
4/// both GPU shader backends.
5///
6/// The values are packed into the GPU frame header so the CPU path and the
7/// shaders sample and bounce identically.
8#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
9pub struct RayTraceSettings {
10    /// Supersampling grid resolution per axis. `1` traces one ray per
11    /// pixel; `4` traces sixteen and averages them. Valid range 1..=4.
12    #[get(type(copy))]
13    pub samples_per_axis: u32,
14    /// Maximum number of secondary bounces after the primary hit. `0`
15    /// still shades the primary hit. Valid range 0..=16.
16    #[get(type(copy))]
17    pub max_bounces: u32,
18}
19
20/// A validated, immutable description of one frame's camera.
21///
22/// Building a [`FrameBasis`] performs every check the packed frame header
23/// and the CPU pixel loop both need: the settings are in range, the
24/// dimensions are usable, the field of view lies in `(0, PI)`, the depth
25/// range satisfies `0 <= near < far` and survives the `f32` narrowing, and
26/// the camera basis is non-degenerate. Holding the result means neither
27/// path has to re-derive the basis or re-run the validation, and neither
28/// can accept a frame the other rejects.
29#[derive(Clone, Copy, Data, Debug, PartialEq)]
30pub(crate) struct FrameBasis {
31    /// The world-space eye position.
32    #[get(pub(crate), type(copy))]
33    pub(crate) eye: Vector3D,
34    /// The unit forward direction, from the eye toward the target.
35    #[get(pub(crate), type(copy))]
36    pub(crate) forward: Vector3D,
37    /// The unit right direction, `forward` crossed with the camera up.
38    #[get(pub(crate), type(copy))]
39    pub(crate) right: Vector3D,
40    /// The unit up direction, `right` crossed with `forward`.
41    #[get(pub(crate), type(copy))]
42    pub(crate) up: Vector3D,
43    /// `tan(fov / 2)`, the factor that makes the rendered vertical field
44    /// of view exactly `fov`.
45    #[get(pub(crate), type(copy))]
46    pub(crate) tan_half_fov: f64,
47    /// `width / height`.
48    #[get(pub(crate), type(copy))]
49    pub(crate) aspect: f64,
50    /// The frame width in pixels.
51    #[get(pub(crate), type(copy))]
52    pub(crate) width: u32,
53    /// The frame height in pixels.
54    #[get(pub(crate), type(copy))]
55    pub(crate) height: u32,
56    /// The near clipping distance used as the primary ray's `t_min`.
57    #[get(pub(crate), type(copy))]
58    pub(crate) near_t: f64,
59    /// The far clipping distance used as the primary ray's `t_max`.
60    #[get(pub(crate), type(copy))]
61    pub(crate) far_t: f64,
62}