From b0315b7ebc16fcbae6c3098db6c824f9057d2a71 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 20 Nov 2023 22:00:34 +0100 Subject: feat(engine): add materials --- engine/src/lighting.rs | 72 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 28 deletions(-) (limited to 'engine/src/lighting.rs') diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs index e7fb901..f14c0b3 100644 --- a/engine/src/lighting.rs +++ b/engine/src/lighting.rs @@ -1,31 +1,13 @@ 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, + ambient: Color, + diffuse: Color, + specular: Color, } impl LightSource @@ -37,9 +19,21 @@ impl LightSource } #[must_use] - pub fn color(&self) -> &Color + pub fn ambient(&self) -> &Color + { + &self.ambient + } + + #[must_use] + pub fn diffuse(&self) -> &Color { - &self.color + &self.diffuse + } + + #[must_use] + pub fn specular(&self) -> &Color + { + &self.specular } pub fn translate(&mut self, translation: Vec3) @@ -52,7 +46,9 @@ impl LightSource pub struct LightSourceBuilder { position: Vec3, - color: Color, + ambient: Color, + diffuse: Color, + specular: Color, } impl LightSourceBuilder @@ -62,7 +58,9 @@ impl LightSourceBuilder { Self { position: Vec3::default(), - color: Color::WHITE_F32, + ambient: Color::WHITE_F32, + diffuse: Color::WHITE_F32, + specular: Color::WHITE_F32, } } @@ -75,9 +73,25 @@ impl LightSourceBuilder } #[must_use] - pub fn color(mut self, color: Color) -> Self + pub fn ambient(mut self, ambient: Color) -> Self + { + self.ambient = ambient; + + self + } + + #[must_use] + pub fn diffuse(mut self, diffuse: Color) -> Self + { + self.diffuse = diffuse; + + self + } + + #[must_use] + pub fn specular(mut self, specular: Color) -> Self { - self.color = color; + self.specular = specular; self } @@ -87,7 +101,9 @@ impl LightSourceBuilder { LightSource { position: self.position.clone(), - color: self.color.clone(), + ambient: self.ambient.clone(), + diffuse: self.diffuse.clone(), + specular: self.specular.clone(), } } } -- cgit v1.2.3-18-g5258