cadmus_core/frontlight/
mod.rs

1mod natural;
2mod premixed;
3mod standard;
4
5pub use self::natural::NaturalFrontlight;
6pub use self::premixed::PremixedFrontlight;
7pub use self::standard::StandardFrontlight;
8use crate::geom::lerp;
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
12pub struct LightLevels {
13    pub intensity: f32,
14    pub warmth: f32,
15}
16
17impl Default for LightLevels {
18    fn default() -> Self {
19        LightLevels {
20            intensity: 0.0,
21            warmth: 0.0,
22        }
23    }
24}
25
26impl LightLevels {
27    pub fn interpolate(self, other: Self, t: f32) -> Self {
28        LightLevels {
29            intensity: lerp(self.intensity, other.intensity, t),
30            warmth: lerp(self.warmth, other.warmth, t),
31        }
32    }
33}
34
35pub trait Frontlight {
36    // value is a percentage.
37    fn set_intensity(&mut self, value: f32);
38    fn set_warmth(&mut self, value: f32);
39    fn levels(&self) -> LightLevels;
40}
41
42impl Frontlight for LightLevels {
43    fn set_intensity(&mut self, value: f32) {
44        self.intensity = value;
45    }
46
47    fn set_warmth(&mut self, value: f32) {
48        self.warmth = value;
49    }
50
51    fn levels(&self) -> LightLevels {
52        *self
53    }
54}