concinnity_core/components/
directional_light.rs1#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
18#[serde(default)]
19pub struct DirectionalLight {
20 pub direction: [f32; 3],
23 pub color: [f32; 3],
25 pub intensity: f32,
27}
28
29impl Default for DirectionalLight {
30 fn default() -> Self {
31 Self {
32 direction: [-0.3, 0.85, 0.4],
33 color: [1.0, 1.0, 1.0],
34 intensity: 1.0,
35 }
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn the_default_sun_points_down_from_above() {
45 let l = DirectionalLight::default();
48 assert!(l.direction[1] > 0.0);
49 assert_eq!(l.color, [1.0, 1.0, 1.0]);
50 assert_eq!(l.intensity, 1.0);
51 }
52
53 #[test]
54 fn an_authored_sun_parses_and_round_trips_through_postcard() {
55 let l: DirectionalLight =
56 serde_json::from_str(r#"{"direction":[0,1,0],"color":[1,0.9,0.7],"intensity":3}"#)
57 .unwrap();
58 assert_eq!(l.direction, [0.0, 1.0, 0.0]);
59 assert_eq!(l.color, [1.0, 0.9, 0.7]);
60 assert_eq!(l.intensity, 3.0);
61
62 let bytes = postcard::to_allocvec(&l).unwrap();
63 let back: DirectionalLight = postcard::from_bytes(&bytes).unwrap();
64 assert_eq!(back.color, [1.0, 0.9, 0.7]);
65 assert_eq!(back.intensity, 3.0);
66 }
67}