Skip to main content

runmat_plot/core/
depth.rs

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