From 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 22:38:52 +0100 Subject: feat(engine): add basic flat lighting --- engine/src/lighting.rs | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 engine/src/lighting.rs (limited to 'engine/src/lighting.rs') diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs new file mode 100644 index 0000000..e7fb901 --- /dev/null +++ b/engine/src/lighting.rs @@ -0,0 +1,93 @@ +use crate::color::Color; +use crate::vector::Vec3; + +#[derive(Debug, Clone)] +pub struct LightSettings +{ + pub ambient_light_strength: f32, + pub specular_light_strength: f32, + pub specular_shininess: u32, +} + +impl Default for LightSettings +{ + fn default() -> Self + { + Self { + ambient_light_strength: 1.0, + specular_light_strength: 0.0, + specular_shininess: 32, + } + } +} + +#[derive(Debug, Clone)] +pub struct LightSource +{ + position: Vec3, + color: Color, +} + +impl LightSource +{ + #[must_use] + pub fn position(&self) -> &Vec3 + { + &self.position + } + + #[must_use] + pub fn color(&self) -> &Color + { + &self.color + } + + pub fn translate(&mut self, translation: Vec3) + { + self.position += translation; + } +} + +#[derive(Debug, Clone, Default)] +pub struct LightSourceBuilder +{ + position: Vec3, + color: Color, +} + +impl LightSourceBuilder +{ + #[must_use] + pub fn new() -> Self + { + Self { + position: Vec3::default(), + color: Color::WHITE_F32, + } + } + + #[must_use] + pub fn position(mut self, position: Vec3) -> Self + { + self.position = position; + + self + } + + #[must_use] + pub fn color(mut self, color: Color) -> Self + { + self.color = color; + + self + } + + #[must_use] + pub fn build(&self) -> LightSource + { + LightSource { + position: self.position.clone(), + color: self.color.clone(), + } + } +} -- cgit v1.2.3-18-g5258