1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Depth and clip-plane policy for 3D rendering.
//!
//! This module centralizes decisions about:
//! - Depth buffer mode (standard vs reversed-Z)
//! - Clip plane selection (static vs dynamic)
//!
//! The goal is robustness across wide scale ranges (LiDAR, radar, etc.).
/// Depth mapping mode for the primary depth buffer.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DepthMode {
/// Standard depth: near maps to 0, far maps to 1.0. Compare: LessEqual. Clear: 1.0.
Standard,
/// Reversed-Z depth: near maps to 1.0, far maps to 0. Compare: GreaterEqual. Clear: 0.0.
ReversedZ,
}
impl Default for DepthMode {
fn default() -> Self {
// Prefer reversed-Z by default for better depth precision on large scenes.
Self::ReversedZ
}
}
/// Clip-plane selection policy.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ClipPolicy {
/// If true, update near/far every frame based on visible scene bounds.
pub dynamic: bool,
/// Smallest near plane distance, in world units. Depth precision is kept by the 1e6 cap on
/// far/near; this floor only keeps near above zero, so a millimeter part a few millimeters
/// from the camera is drawn rather than clipped.
pub min_near: f32,
/// Multiply the computed near by this padding factor (<1 pulls near closer).
pub near_padding: f32,
/// Multiply the computed far by this padding factor (>1 pushes far further).
pub far_padding: f32,
/// Clamp far to this max (safety against runaway bounds).
pub max_far: f32,
}
impl Default for ClipPolicy {
fn default() -> Self {
Self {
dynamic: true,
min_near: 1.0e-6,
near_padding: 0.8,
far_padding: 1.2,
max_far: 1.0e9,
}
}
}