use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct DirectionalLightDesc {
pub direction: [f32; 3],
pub color: [f32; 3],
pub intensity_lux: f32,
}
impl Default for DirectionalLightDesc {
fn default() -> Self {
Self {
direction: [0.0, -1.0, 0.0],
color: [1.0, 1.0, 1.0],
intensity_lux: 100_000.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct PointLightDesc {
pub position: [f32; 3],
pub color: [f32; 3],
pub intensity_lumens: f32,
pub range: f32,
}
impl Default for PointLightDesc {
fn default() -> Self {
Self {
position: [0.0, 3.0, 0.0],
color: [1.0, 1.0, 1.0],
intensity_lumens: 800.0,
range: 10.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct SpotLightDesc {
pub position: [f32; 3],
pub direction: [f32; 3],
pub color: [f32; 3],
pub intensity_lumens: f32,
pub range: f32,
pub inner_cos: f32,
pub outer_cos: f32,
}
impl Default for SpotLightDesc {
fn default() -> Self {
Self {
position: [0.0, 3.0, 0.0],
direction: [0.0, -1.0, 0.0],
color: [1.0, 1.0, 1.0],
intensity_lumens: 800.0,
range: 10.0,
inner_cos: 0.9659, outer_cos: 0.8660, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn directional_default() {
let d = DirectionalLightDesc::default();
assert_eq!(d.direction, [0.0, -1.0, 0.0]);
assert!(d.intensity_lux > 0.0);
}
#[test]
fn point_default() {
let p = PointLightDesc::default();
assert!(p.range > 0.0);
assert!(p.intensity_lumens > 0.0);
}
#[test]
fn spot_cone_angles() {
let s = SpotLightDesc::default();
assert!(s.inner_cos > s.outer_cos, "inner cone must be tighter than outer");
}
#[test]
fn serde_roundtrip() {
let d = DirectionalLightDesc::default();
let json = serde_json::to_string(&d).unwrap();
let back: DirectionalLightDesc = serde_json::from_str(&json).unwrap();
assert_eq!(d, back);
}
}