summaryrefslogtreecommitdiff
path: root/engine/src/lighting.rs
blob: e7fb9011fda0dd1b5e9f79ca024f02c98f097e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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(),
        }
    }
}