Skip to main content

euv_core/game/engine3d/raytrace/denoiser/
struct.rs

1use super::*;
2
3/// Persistent primary G-buffer storing world normals, linear depths, base albedo, and hit mask for SVGF edge-stopping.
4#[derive(Clone, Data, Debug, Default, PartialEq)]
5pub struct RtGBuffer {
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    /// Primary surface base albedo per pixel (`len == width * height`).
13    pub(crate) albedo: Vec<Vec3>,
14    /// Primary world-space shading normal per pixel (`len == width * height`).
15    pub(crate) normal: Vec<Vec3>,
16    /// Primary linear hit distance in meters (`RT_SKY_DEPTH` on sky misses).
17    pub(crate) depth: Vec<f32>,
18    /// Per-pixel geometry hit flag (`1` = geometry hit, `0` = background sky).
19    pub(crate) hit_mask: Vec<u8>,
20}
21
22/// Progressive temporal radiance and luminance-moment (`M1`, `M2`) accumulator with automatic camera/scene motion reset.
23#[derive(Clone, Data, Debug, Default, PartialEq)]
24pub struct TemporalAccumulator {
25    /// Buffer width in pixels.
26    #[get(type(copy))]
27    pub(crate) width: u32,
28    /// Buffer height in pixels.
29    #[get(type(copy))]
30    pub(crate) height: u32,
31    /// Running mean linear HDR radiance per pixel.
32    pub(crate) radiance: Vec<Vec3>,
33    /// Running first luminance moment `E[L]` per pixel.
34    pub(crate) moment_1: Vec<f32>,
35    /// Running second luminance moment `E[L^2]` per pixel.
36    pub(crate) moment_2: Vec<f32>,
37    /// Accumulated sample count per pixel.
38    pub(crate) sample_counts: Vec<u32>,
39    /// Cached camera fingerprint used to detect camera motion.
40    #[get(type(copy))]
41    pub(crate) camera_fingerprint: u64,
42    /// Cached scene revision used to detect dynamic scene edits.
43    #[get(type(copy))]
44    pub(crate) scene_revision: u64,
45    /// Optional history length cap (`0` = unbiased unlimited progressive accumulation).
46    #[get(type(copy))]
47    pub(crate) max_history_samples: u32,
48    /// Total automatic or explicit accumulation resets performed.
49    #[get(type(copy))]
50    pub(crate) reset_count: u64,
51}
52
53/// Edge-stopping and iteration configuration parameters for `SvgfDenoiser`.
54#[derive(Clone, Copy, Data, Debug, PartialEq)]
55pub struct SvgfConfig {
56    /// Number of À-Trous wavelet spatial passes (`1..=5`, step sizes `1, 2, 4, 8, 16`).
57    #[get(type(copy))]
58    pub(crate) iterations: u32,
59    /// Normal similarity exponent (`max(0, n_p · n_q)^phi_normal`).
60    #[get(type(copy))]
61    pub(crate) phi_normal: f32,
62    /// Linear depth edge-stopping sensitivity.
63    #[get(type(copy))]
64    pub(crate) phi_depth: f32,
65    /// Luminance variance edge-stopping sensitivity.
66    #[get(type(copy))]
67    pub(crate) phi_luma: f32,
68    /// Minimum variance floor preventing over-strict luminance rejection in low-sample regions.
69    #[get(type(copy))]
70    pub(crate) variance_floor: f32,
71    /// When `true`, demodulates primary albedo before filtering and remodulates after to preserve fine textures.
72    #[get(type(copy))]
73    pub(crate) demodulate_albedo: bool,
74}
75
76/// Zero-steady-state-allocation multi-pass edge-stopping À-Trous wavelet SVGF denoiser.
77#[derive(Clone, Data, Debug, Default, PartialEq)]
78pub struct SvgfDenoiser {
79    /// Edge-stopping and pass-count settings.
80    #[get(type(copy))]
81    pub(crate) config: SvgfConfig,
82    /// Allocated viewport width in pixels.
83    #[get(type(copy))]
84    pub(crate) width: u32,
85    /// Allocated viewport height in pixels.
86    #[get(type(copy))]
87    pub(crate) height: u32,
88    /// Persistent ping HDR color scratch buffer.
89    #[get(skip)]
90    #[get_mut(skip)]
91    #[set(skip)]
92    pub(crate) ping_color: Vec<Vec3>,
93    /// Persistent pong HDR color scratch buffer.
94    #[get(skip)]
95    #[get_mut(skip)]
96    #[set(skip)]
97    pub(crate) pong_color: Vec<Vec3>,
98    /// Persistent ping luminance variance scratch buffer.
99    #[get(skip)]
100    #[get_mut(skip)]
101    #[set(skip)]
102    pub(crate) ping_variance: Vec<f32>,
103    /// Persistent pong luminance variance scratch buffer.
104    #[get(skip)]
105    #[get_mut(skip)]
106    #[set(skip)]
107    pub(crate) pong_variance: Vec<f32>,
108}