euv_core/game/engine3d/occlusion/struct.rs
1use super::*;
2
3/// Conservative reverse-Z Hierarchical Z-Buffer (Hi-Z) minimum-depth mip pyramid for O(1) occlusion culling.
4#[derive(Clone, Data, Debug, Default)]
5pub struct HiZPyramid {
6 /// Viewport width in pixels covered by this Hi-Z pyramid.
7 #[get(type(copy))]
8 pub(crate) viewport_width: usize,
9 /// Viewport height in pixels covered by this Hi-Z pyramid.
10 #[get(type(copy))]
11 pub(crate) viewport_height: usize,
12 /// Base cell edge size in pixels (typically `8`).
13 #[get(type(copy))]
14 pub(crate) cell_size_px: usize,
15 /// Whether the pyramid holds valid reverse-Z depth data for occlusion queries.
16 #[get(type(copy))]
17 pub(crate) valid: bool,
18 /// Mip levels from finest (`levels[0]`) to coarsest (`1x1`), each storing conservative minimum `1/w`.
19 #[get(skip)]
20 #[get_mut(skip)]
21 #[set(skip)]
22 pub(crate) levels: Vec<Vec<f32>>,
23 /// Width and height in cells for each mip level aligned 1:1 with `levels`.
24 #[get(skip)]
25 #[get_mut(skip)]
26 #[set(skip)]
27 pub(crate) level_dims: Vec<(usize, usize)>,
28}
29
30/// Single node inside a UE5 Nanite-style hierarchical cluster DAG storing triangle range, normal cone, and parent/self geometric errors.
31#[derive(Clone, Copy, Data, Debug, PartialEq)]
32pub struct NaniteClusterNode {
33 /// Starting triangle index in the owning `Mesh3D::indices` slice.
34 #[get(type(copy))]
35 pub(crate) first_tri: u32,
36 /// Number of triangles represented by this cluster node.
37 #[get(type(copy))]
38 pub(crate) tri_count: u32,
39 /// Tight local-space bounding box enclosing all cluster triangles.
40 #[get(type(copy))]
41 pub(crate) bounds: AxisAlignedBox3D,
42 /// Outward average normal cone axis for cluster backface culling.
43 #[get(type(copy))]
44 pub(crate) cone_axis: Vec3,
45 /// Minimum dot product between member face normals and `cone_axis`.
46 #[get(type(copy))]
47 pub(crate) cone_cutoff: f32,
48 /// Intrinsic local geometric error of this cluster in meters (`0.0` at leaf `LOD0`).
49 #[get(type(copy))]
50 pub(crate) cluster_error: f32,
51 /// Intrinsic geometric error of this node's parent group in meters (`f32::INFINITY` at root).
52 #[get(type(copy))]
53 pub(crate) parent_error: f32,
54 /// Hierarchy LOD depth (`0` = finest leaf cluster, higher = coarser group).
55 #[get(type(copy))]
56 pub(crate) lod_level: u8,
57 /// Starting index of child nodes inside `NaniteClusterDag::nodes` (`0` for leaf nodes).
58 #[get(type(copy))]
59 pub(crate) child_start: u32,
60 /// Number of child nodes (`0` for leaf clusters).
61 #[get(type(copy))]
62 pub(crate) child_count: u16,
63}
64
65/// Telemetry emitted by a single UE5 Nanite cluster DAG selection cut.
66#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
67pub struct NaniteCutStats {
68 /// Cluster nodes selected for rasterization after frustum, cone, and Hi-Z culling.
69 #[get(type(copy))]
70 pub(crate) clusters_drawn: usize,
71 /// Cluster nodes rejected by 6-plane view frustum culling.
72 #[get(type(copy))]
73 pub(crate) clusters_frustum_culled: usize,
74 /// Cluster nodes rejected by outward normal-cone backface culling.
75 #[get(type(copy))]
76 pub(crate) clusters_cone_culled: usize,
77 /// Cluster nodes rejected by conservative reverse-Z Hi-Z occlusion culling.
78 #[get(type(copy))]
79 pub(crate) clusters_hiz_culled: usize,
80 /// Cluster nodes rejected because their projected screen area fell below one pixel.
81 #[get(type(copy))]
82 pub(crate) clusters_micro_culled: usize,
83}
84
85/// Hierarchical cluster Directed Acyclic Graph enabling continuous screen-error LOD cuts and combined frustum/cone/Hi-Z culling.
86#[derive(Clone, Data, Debug, Default, PartialEq)]
87pub struct NaniteClusterDag {
88 /// Flat node array ordered bottom-up with root group nodes at `root_start..nodes.len()`.
89 pub(crate) nodes: Vec<NaniteClusterNode>,
90 /// Starting index of top-level root nodes in `nodes`.
91 #[get(type(copy))]
92 pub(crate) root_start: usize,
93 /// Number of hierarchy levels in this DAG (`>= 1` for non-empty meshes).
94 #[get(type(copy))]
95 pub(crate) level_count: usize,
96}
97
98/// Immutable per-object view and culling context passed to `NaniteClusterDag::select_cut`.
99#[derive(Clone, Copy, Data, Debug)]
100pub struct NaniteCutContext<'a> {
101 /// Active camera world position.
102 #[get(type(copy))]
103 pub(crate) camera_position: Vec3,
104 /// Object local-to-world transform matrix.
105 #[get(type(copy))]
106 pub(crate) model_matrix: Mat4,
107 /// Active frame view-projection matrix.
108 #[get(type(copy))]
109 pub(crate) view_projection: Mat4,
110 /// Inverse-transpose 3x3 world normal basis.
111 #[get(type(copy))]
112 pub(crate) normal_basis: [Vec3; 3],
113 /// Active 6-plane camera frustum.
114 #[get(type(copy))]
115 pub(crate) frustum: Frustum3D,
116 /// Optional conservative reverse-Z Hi-Z occlusion pyramid.
117 #[get(skip)]
118 #[get_mut(skip)]
119 #[set(skip)]
120 pub(crate) hiz_pyramid: Option<&'a HiZPyramid>,
121 /// Whether normal-cone backface culling is enabled (closed positive-scale meshes).
122 #[get(type(copy))]
123 pub(crate) cull_backface: bool,
124 /// Projected viewport focal length in pixels.
125 #[get(type(copy))]
126 pub(crate) focal_px: f32,
127 /// Maximum tolerated geometric error in pixels before descending into finer child clusters.
128 #[get(type(copy))]
129 pub(crate) error_threshold_px: f32,
130 /// Camera near clip plane distance in meters.
131 #[get(type(copy))]
132 pub(crate) near_plane: f32,
133 /// Viewport width in pixels.
134 #[get(type(copy))]
135 pub(crate) viewport_width: f32,
136 /// Viewport height in pixels.
137 #[get(type(copy))]
138 pub(crate) viewport_height: f32,
139 /// Maximum triangle count of the owning mesh for bounds clamping.
140 #[get(type(copy))]
141 pub(crate) total_triangles: usize,
142}