cvkg_render_gpu/types/
lod.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum EffectLod {
5 Full,
7 Reduced,
9 Minimal,
11}
12
13impl EffectLod {
14 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 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 pub fn enable_volumetric(&self) -> bool {
34 matches!(self, EffectLod::Full)
35 }
36
37 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}