diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-12 22:38:52 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-12 22:57:19 +0100 |
commit | 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 (patch) | |
tree | ed1b0dd30e801b9a70537b9806a445e4212978b3 /engine/src/lighting.rs | |
parent | 67023d6a095f457a2579367d59d13c6c804e7108 (diff) |
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/src/lighting.rs')
-rw-r--r-- | engine/src/lighting.rs | 93 |
1 files changed, 93 insertions, 0 deletions
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<f32>, + color: Color<f32>, +} + +impl LightSource +{ + #[must_use] + pub fn position(&self) -> &Vec3<f32> + { + &self.position + } + + #[must_use] + pub fn color(&self) -> &Color<f32> + { + &self.color + } + + pub fn translate(&mut self, translation: Vec3<f32>) + { + self.position += translation; + } +} + +#[derive(Debug, Clone, Default)] +pub struct LightSourceBuilder +{ + position: Vec3<f32>, + color: Color<f32>, +} + +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<f32>) -> Self + { + self.position = position; + + self + } + + #[must_use] + pub fn color(mut self, color: Color<f32>) -> Self + { + self.color = color; + + self + } + + #[must_use] + pub fn build(&self) -> LightSource + { + LightSource { + position: self.position.clone(), + color: self.color.clone(), + } + } +} |