euv_core/game/engine3d/raytrace/session/struct.rs
1use super::*;
2
3/// Complete configuration descriptor for a reusable `RaytraceSession`.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct RaytraceConfig {
6 /// Viewport width in pixels.
7 #[get(type(copy))]
8 pub(crate) width: u32,
9 /// Viewport height in pixels.
10 #[get(type(copy))]
11 pub(crate) height: u32,
12 /// Active ray-tracing integrator mode.
13 #[get(type(copy))]
14 pub(crate) integrator: RtIntegratorMode,
15 /// Display tone-mapping view transform.
16 #[get(type(copy))]
17 pub(crate) tonemap: RtTonemapMode,
18 /// Linear HDR exposure multiplier applied before tone mapping.
19 #[get(type(copy))]
20 pub(crate) exposure: f32,
21 /// Square tile edge size in pixels for progressive budgeted stepping.
22 #[get(type(copy))]
23 pub(crate) tile_size: u32,
24 /// Enables multi-pass À-Trous SVGF spatial denoising on the accumulated HDR buffer.
25 #[get(type(copy))]
26 pub(crate) enable_denoiser: bool,
27 /// Whitted integrator settings.
28 #[get(type(copy))]
29 pub(crate) whitted: WhittedIntegrator,
30 /// Monte Carlo PBR path-tracer settings.
31 #[get(type(copy))]
32 pub(crate) path_trace: PathTraceIntegrator,
33 /// Ray-Traced Ambient Occlusion settings.
34 #[get(type(copy))]
35 pub(crate) rtao: RtaoIntegrator,
36 /// Fast 1-spp interactive hybrid preview settings.
37 #[get(type(copy))]
38 pub(crate) hybrid_preview: HybridPreviewIntegrator,
39 /// SVGF denoiser edge-stopping parameters.
40 #[get(type(copy))]
41 pub(crate) svgf: SvgfConfig,
42 /// Deterministic RNG base seed.
43 #[get(type(copy))]
44 pub(crate) seed: u32,
45}
46
47/// Real-time ray-tracing telemetry reported by `RaytraceSession` after each progressive step or pass.
48#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
49pub struct RaytraceStats {
50 /// Average accumulated samples per pixel across the viewport.
51 #[get(type(copy))]
52 pub(crate) samples_per_pixel: f32,
53 /// Number of complete full-frame passes accumulated since the last reset.
54 #[get(type(copy))]
55 pub(crate) completed_passes: u32,
56 /// Cumulative primary camera rays cast since the last reset.
57 #[get(type(copy))]
58 pub(crate) primary_rays: u64,
59 /// Cumulative shadow and ambient-occlusion rays cast since the last reset.
60 #[get(type(copy))]
61 pub(crate) shadow_rays: u64,
62 /// Cumulative secondary reflection, refraction, and indirect bounce rays cast since the last reset.
63 #[get(type(copy))]
64 pub(crate) bounce_rays: u64,
65 /// Cumulative total rays cast since the last reset.
66 #[get(type(copy))]
67 pub(crate) total_rays: u64,
68 /// Rays cast during the most recent `render_progressive_step` call.
69 #[get(type(copy))]
70 pub(crate) last_step_rays: u64,
71 /// Wall-clock duration in milliseconds of the most recent step (`0.0` on wasm32 without host clock).
72 #[get(type(copy))]
73 pub(crate) last_step_ms: f32,
74 /// Effective throughput in millions of rays per second (`MRays/sec`) for the most recent step.
75 #[get(type(copy))]
76 pub(crate) mrays_per_sec: f32,
77 /// Wall-clock duration in milliseconds spent in SVGF denoising on the most recent step.
78 #[get(type(copy))]
79 pub(crate) denoise_ms: f32,
80 /// Pixels traced so far in the current progressive frame pass.
81 #[get(type(copy))]
82 pub(crate) pixels_traced_in_pass: u32,
83 /// Total pixel count (`width * height`) of the viewport.
84 #[get(type(copy))]
85 pub(crate) total_pixels: u32,
86}
87
88/// Zero-steady-state-allocation reusable ray-tracing session owning persistent HDR accumulation, G-buffers, SVGF denoiser, and tone-mapped RGBA8 output.
89#[derive(Clone, Data, Debug)]
90pub struct RaytraceSession {
91 /// Active session configuration.
92 #[get(type(copy))]
93 pub(crate) config: RaytraceConfig,
94 /// Progressive temporal radiance and variance moment accumulator.
95 pub(crate) accumulator: TemporalAccumulator,
96 /// Primary G-buffer storing world normals, linear depth, albedo, and geometry hit masks.
97 pub(crate) gbuffer: RtGBuffer,
98 /// Multi-pass edge-stopping À-Trous SVGF denoiser.
99 pub(crate) denoiser: SvgfDenoiser,
100 /// Pre-allocated per-pixel luminance variance scratch buffer feeding SVGF.
101 #[get(skip)]
102 #[get_mut(skip)]
103 #[set(skip)]
104 pub(crate) variance_scratch: Vec<f32>,
105 /// Persistent denoised (or raw accumulated) linear HDR output buffer.
106 pub(crate) denoised_hdr: Vec<Vec3>,
107 /// Persistent tone-mapped sRGB RGBA8 output framebuffer (`len == width * height * 4`).
108 pub(crate) rgba8_output: Vec<u8>,
109 /// Latest session telemetry snapshot.
110 #[get(type(copy))]
111 pub(crate) stats: RaytraceStats,
112 /// Current progressive tile cursor within `[0, total_tiles)`.
113 #[get(type(copy))]
114 pub(crate) tile_cursor: u32,
115 /// Current full-frame pass index used for quasi-random jitter and RNG decorrelation.
116 #[get(type(copy))]
117 pub(crate) pass_index: u32,
118}
119
120/// Cross-platform monotonic timer token wrapping `Instant` on native targets and a zero-cost placeholder on `wasm32`.
121#[derive(Clone, Copy, Debug)]
122pub(crate) struct RtTimer {
123 /// Captured native monotonic start timestamp.
124 #[cfg(not(target_arch = "wasm32"))]
125 pub(crate) start: Instant,
126 /// Zero-cost placeholder token on `wasm32`.
127 #[cfg(target_arch = "wasm32")]
128 pub(crate) start: u8,
129}
130
131/// Disjoint row-range mutable pointer wrapper for parallel tonemapping into RGBA8 buffers on native targets.
132#[cfg(not(target_arch = "wasm32"))]
133#[derive(Clone, Copy)]
134pub(crate) struct RgbaRowMutView {
135 /// Base raw pointer to destination RGBA8 bytes.
136 pub(crate) ptr: *mut u8,
137}
138
139/// Disjoint row-range mutable pointer bundle for parallel ray-tracing pass accumulation on native targets.
140#[cfg(not(target_arch = "wasm32"))]
141#[derive(Clone, Copy)]
142pub(crate) struct RtPassMutView {
143 /// Base raw pointer to `TemporalAccumulator::radiance`.
144 pub(crate) radiance: *mut Vec3,
145 /// Base raw pointer to `TemporalAccumulator::moment_1`.
146 pub(crate) moment_1: *mut f32,
147 /// Base raw pointer to `TemporalAccumulator::moment_2`.
148 pub(crate) moment_2: *mut f32,
149 /// Base raw pointer to `TemporalAccumulator::sample_counts`.
150 pub(crate) sample_counts: *mut u32,
151 /// Base raw pointer to `RtGBuffer::albedo`.
152 pub(crate) albedo: *mut Vec3,
153 /// Base raw pointer to `RtGBuffer::normal`.
154 pub(crate) normal: *mut Vec3,
155 /// Base raw pointer to `RtGBuffer::depth`.
156 pub(crate) depth: *mut f32,
157 /// Base raw pointer to `RtGBuffer::hit_mask`.
158 pub(crate) hit_mask: *mut u8,
159}