use scenix_core::Color;
use crate::{ShadowConfig, positive};
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PointLight {
pub color: Color,
pub intensity: f32,
pub range: f32,
pub decay: f32,
pub shadow: Option<ShadowConfig>,
}
impl PointLight {
#[inline]
pub fn new(color: Color, intensity: f32, range: f32) -> Self {
Self {
color,
intensity,
range: range.max(0.0),
decay: 2.0,
shadow: None,
}
}
#[inline]
pub fn decay(mut self, decay: f32) -> Self {
self.decay = positive(decay, 2.0);
self
}
#[inline]
pub const fn shadow(mut self, shadow: ShadowConfig) -> Self {
self.shadow = Some(shadow);
self
}
}
impl Default for PointLight {
#[inline]
fn default() -> Self {
Self::new(Color::WHITE, 1.0, 0.0)
}
}