diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
commit | b0315b7ebc16fcbae6c3098db6c824f9057d2a71 (patch) | |
tree | c7473fbdbcc59aff933790892ee015a6f05d8565 /engine/src/lighting.rs | |
parent | a65c8abcae46b382b2e1bb7cc5d13768325083b4 (diff) |
feat(engine): add materials
Diffstat (limited to 'engine/src/lighting.rs')
-rw-r--r-- | engine/src/lighting.rs | 72 |
1 files changed, 44 insertions, 28 deletions
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 @@ -2,30 +2,12 @@ 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<f32>, - color: Color<f32>, + ambient: Color<f32>, + diffuse: Color<f32>, + specular: Color<f32>, } impl LightSource @@ -37,9 +19,21 @@ impl LightSource } #[must_use] - pub fn color(&self) -> &Color<f32> + pub fn ambient(&self) -> &Color<f32> + { + &self.ambient + } + + #[must_use] + pub fn diffuse(&self) -> &Color<f32> { - &self.color + &self.diffuse + } + + #[must_use] + pub fn specular(&self) -> &Color<f32> + { + &self.specular } pub fn translate(&mut self, translation: Vec3<f32>) @@ -52,7 +46,9 @@ impl LightSource pub struct LightSourceBuilder { position: Vec3<f32>, - color: Color<f32>, + ambient: Color<f32>, + diffuse: Color<f32>, + specular: Color<f32>, } 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<f32>) -> Self + pub fn ambient(mut self, ambient: Color<f32>) -> Self + { + self.ambient = ambient; + + self + } + + #[must_use] + pub fn diffuse(mut self, diffuse: Color<f32>) -> Self + { + self.diffuse = diffuse; + + self + } + + #[must_use] + pub fn specular(mut self, specular: Color<f32>) -> 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(), } } } |