Skip to main content

cvkg_render_gpu/types/
lod.rs

1/// Effect LOD (Level of Detail) based on active effect count.
2/// When many effects are stacked, reduces quality to maintain frame rate.
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum EffectLod {
5    /// All effects at full quality.
6    Full,
7    /// Reduce blur mip levels, disable volumetric.
8    Reduced,
9    /// Only essential passes (geometry, UI, composite).
10    Minimal,
11}
12
13impl EffectLod {
14    /// Determine LOD from the number of active effects.
15    pub fn from_active_count(count: usize) -> Self {
16        match count {
17            0..=2 => EffectLod::Full,
18            3..=4 => EffectLod::Reduced,
19            _ => EffectLod::Minimal,
20        }
21    }
22
23    /// Number of blur mip levels at this LOD.
24    pub fn blur_mip_levels(&self) -> u32 {
25        match self {
26            EffectLod::Full => 7,
27            EffectLod::Reduced => 4,
28            EffectLod::Minimal => 2,
29        }
30    }
31
32    /// Whether volumetric effects should be enabled at this LOD.
33    pub fn enable_volumetric(&self) -> bool {
34        matches!(self, EffectLod::Full)
35    }
36
37    /// Whether bloom should be enabled at this LOD.
38    pub fn enable_bloom(&self) -> bool {
39        !matches!(self, EffectLod::Minimal)
40    }
41}
42
43#[cfg(test)]
44mod p1_28_effect_lod_tests {
45    use super::EffectLod;
46
47    #[test]
48    fn full_quality_for_few_effects() {
49        assert_eq!(EffectLod::from_active_count(0), EffectLod::Full);
50        assert_eq!(EffectLod::from_active_count(1), EffectLod::Full);
51        assert_eq!(EffectLod::from_active_count(2), EffectLod::Full);
52    }
53
54    #[test]
55    fn reduced_quality_for_moderate_effects() {
56        assert_eq!(EffectLod::from_active_count(3), EffectLod::Reduced);
57        assert_eq!(EffectLod::from_active_count(4), EffectLod::Reduced);
58    }
59
60    #[test]
61    fn minimal_quality_for_many_effects() {
62        assert_eq!(EffectLod::from_active_count(5), EffectLod::Minimal);
63        assert_eq!(EffectLod::from_active_count(10), EffectLod::Minimal);
64    }
65
66    #[test]
67    fn blur_mip_levels_scale_with_lod() {
68        assert_eq!(EffectLod::Full.blur_mip_levels(), 7);
69        assert_eq!(EffectLod::Reduced.blur_mip_levels(), 4);
70        assert_eq!(EffectLod::Minimal.blur_mip_levels(), 2);
71    }
72
73    #[test]
74    fn volumetric_only_at_full() {
75        assert!(EffectLod::Full.enable_volumetric());
76        assert!(!EffectLod::Reduced.enable_volumetric());
77        assert!(!EffectLod::Minimal.enable_volumetric());
78    }
79
80    #[test]
81    fn bloom_disabled_at_minimal() {
82        assert!(EffectLod::Full.enable_bloom());
83        assert!(EffectLod::Reduced.enable_bloom());
84        assert!(!EffectLod::Minimal.enable_bloom());
85    }
86}