scenix_light/
directional.rs1use scenix_core::Color;
2use scenix_math::Vec3;
3
4use crate::ShadowConfig;
5
6#[derive(Clone, Copy, Debug, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct DirectionalLight {
10 pub direction: Vec3,
12 pub color: Color,
14 pub intensity: f32,
16 pub shadow: Option<ShadowConfig>,
18}
19
20impl DirectionalLight {
21 #[inline]
23 pub fn new(direction: Vec3, color: Color, intensity: f32) -> Self {
24 let direction = direction.normalize();
25 Self {
26 direction: if direction == Vec3::ZERO {
27 Vec3::NEG_Z
28 } else {
29 direction
30 },
31 color,
32 intensity,
33 shadow: None,
34 }
35 }
36
37 #[inline]
39 pub const fn shadow(mut self, shadow: ShadowConfig) -> Self {
40 self.shadow = Some(shadow);
41 self
42 }
43}
44
45impl Default for DirectionalLight {
46 #[inline]
47 fn default() -> Self {
48 Self::new(Vec3::NEG_Z, Color::WHITE, 1.0)
49 }
50}