euv_core/game/engine3d/lumen/struct.rs
1use super::*;
2
3/// Single spatial-hash cell storing temporally filtered multi-bounce indirect irradiance and occlusion in `LumenRadianceCache`.
4#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
5pub struct LumenCacheCell {
6 /// Non-zero spatial hash key identifying `(voxel_x, voxel_y, voxel_z, normal_bucket, cascade)`.
7 #[get(type(copy))]
8 pub(crate) key: u64,
9 /// Temporally filtered linear HDR indirect diffuse red radiance.
10 #[get(type(copy))]
11 pub(crate) irradiance_r: f32,
12 /// Temporally filtered linear HDR indirect diffuse green radiance.
13 #[get(type(copy))]
14 pub(crate) irradiance_g: f32,
15 /// Temporally filtered linear HDR indirect diffuse blue radiance.
16 #[get(type(copy))]
17 pub(crate) irradiance_b: f32,
18 /// Temporally filtered ambient occlusion factor in `[0.35, 1.0]`.
19 #[get(type(copy))]
20 pub(crate) ambient_occlusion: f32,
21 /// Temporally filtered directional sun visibility factor in `[0.0, 1.0]`.
22 #[get(type(copy))]
23 pub(crate) sun_visibility: f32,
24 /// Accumulated sample confidence weight capped at `LUMEN_MAX_TEMPORAL_WEIGHT`.
25 #[get(type(copy))]
26 pub(crate) sample_weight: f32,
27 /// Monotonic frame index when this cell was last refreshed.
28 #[get(type(copy))]
29 pub(crate) last_frame: u32,
30}
31
32/// Telemetry counters describing hit rate and occupancy of `LumenRadianceCache`.
33#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
34pub struct LumenCacheStats {
35 /// Total active occupied cells in the world-space radiance hash table.
36 #[get(type(copy))]
37 pub(crate) active_cells: usize,
38 /// Cache hits served during the most recent frame.
39 #[get(type(copy))]
40 pub(crate) frame_hits: u64,
41 /// Cache misses encountered during the most recent frame.
42 #[get(type(copy))]
43 pub(crate) frame_misses: u64,
44 /// Total temporal updates accumulated into the cache.
45 #[get(type(copy))]
46 pub(crate) total_updates: u64,
47}
48
49/// UE5 Lumen-style World-Space Two-Cascade Spatial-Hash Radiance Cache enabling zero-allocation O(1) multi-bounce GI feedback.
50#[derive(Clone, Data, Debug)]
51pub struct LumenRadianceCache {
52 /// Power-of-two slot mask (`cells.len() - 1`).
53 #[get(type(copy))]
54 pub(crate) slot_mask: usize,
55 /// Monotonic frame counter driving stale-entry eviction.
56 #[get(type(copy))]
57 pub(crate) current_frame: u32,
58 /// Last directional sun vector validating cache freshness across lighting changes.
59 #[get(type(copy))]
60 pub(crate) cached_sun_dir: Vec3,
61 /// Number of occupied cells currently storing valid radiance.
62 #[get(type(copy))]
63 pub(crate) active_cells: usize,
64 /// Cumulative temporal updates recorded across frames.
65 #[get(type(copy))]
66 pub(crate) total_updates: u64,
67 /// Fixed-capacity open-addressed hash table cells.
68 #[get(skip)]
69 #[get_mut(skip)]
70 #[set(skip)]
71 pub(crate) cells: Vec<LumenCacheCell>,
72}
73
74/// Result of analytically reprojecting a current-frame world probe into the previous frame's coarse RT probe grid.
75#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
76pub struct LumenReprojectedProbe {
77 /// Linear index inside `prev_rt_probes` (`prev_gy * prev_gw + prev_gx`).
78 #[get(type(copy))]
79 pub(crate) prev_index: usize,
80 /// Reprojected previous-frame coarse probe column index.
81 #[get(type(copy))]
82 pub(crate) prev_gx: usize,
83 /// Reprojected previous-frame coarse probe row index.
84 #[get(type(copy))]
85 pub(crate) prev_gy: usize,
86 /// Reprojected previous-frame linear camera depth (`prev_clip_w`).
87 #[get(type(copy))]
88 pub(crate) prev_depth: f32,
89}