use ecs::{Component, Sole}; use crate::color::Color; use crate::util::builder; builder! { #[builder(name = PointLightBuilder, derives = (Debug, Clone))] #[derive(Debug, Clone, Component)] #[non_exhaustive] pub struct PointLight { pub diffuse: Color, pub specular: Color, pub attenuation_params: AttenuationParams, } } impl PointLight { pub fn builder() -> PointLightBuilder { PointLightBuilder::default() } } impl Default for PointLight { fn default() -> Self { Self { diffuse: Color { red: 0.5, green: 0.5, blue: 0.5 }, specular: Color { red: 1.0, green: 1.0, blue: 1.0 }, attenuation_params: AttenuationParams::default(), } } } impl Default for PointLightBuilder { fn default() -> Self { PointLight::default().into() } } /// Parameters for light [attenuation](https://en.wikipedia.org/wiki/Attenuation). #[derive(Debug, Clone)] pub struct AttenuationParams { pub constant: f32, pub linear: f32, pub quadratic: f32, } impl Default for AttenuationParams { fn default() -> Self { Self { constant: 1.0, linear: 0.0, quadratic: 0.0, } } } builder! { /// Global light properties. #[builder(name = GlobalLightBuilder, derives = (Debug, Clone, Default))] #[derive(Debug, Clone, Default, Sole)] #[non_exhaustive] pub struct GlobalLight { pub ambient: Color, } } impl GlobalLight { #[must_use] pub fn builder() -> GlobalLightBuilder { GlobalLightBuilder::default() } }