use ecs::{Component, Sole}; use crate::color::Color; use crate::data_types::vector::Vec3; use crate::util::builder; builder! { #[builder(name = PointLightBuilder, derives = (Debug, Clone))] #[derive(Debug, Clone, Component)] #[non_exhaustive] pub struct PointLight { pub position: Vec3, pub diffuse: Color, pub specular: Color, pub attenuation_params: AttenuationParams, } } impl PointLight { #[must_use] pub fn builder() -> PointLightBuilder { PointLightBuilder::default() } } impl Default for PointLight { fn default() -> Self { Self { position: Vec3::default(), 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 { #[must_use] fn default() -> Self { Self { constant: 1.0, linear: 0.0, quadratic: 0.0, } } } builder! { #[builder(name = DirectionalLightBuilder, derives = (Debug, Default, Clone))] #[derive(Debug, Default, Clone, Component)] #[non_exhaustive] pub struct DirectionalLight { pub diffuse: Color, pub specular: Color, pub direction: Vec3, } } impl DirectionalLight { #[must_use] pub fn builder() -> DirectionalLightBuilder { DirectionalLightBuilder::default() } } 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() } }