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
use crate::color::Rgb;
use crate::color::Rgbf;
use crate::math::Vec3;
use crate::math::Vec4;
use crate::pipeline::ShaderLight;
#[derive(Copy, Clone, Debug)]
pub struct Light {
pub coords: Vec3,
pub color: Rgb,
pub brightness: f32,
pub light_type: LightType,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LightType {
Directional,
Point,
}
impl Light {
pub fn directional(color: impl Into<Rgb>, direction: impl Into<Vec3>) -> Self {
Self {
light_type: LightType::Directional,
coords: direction.into().unit(),
color: color.into(),
brightness: 1.0,
}
}
pub fn point(color: impl Into<Rgb>, position: impl Into<Vec3>) -> Self {
Self {
light_type: LightType::Point,
coords: position.into(),
color: color.into(),
brightness: 1.0,
}
}
pub(crate) fn none() -> Self {
Self::point(Rgb::clear(), [0.0, 0.0, 0.0])
}
pub(crate) const fn is_none(&self) -> bool {
self.color.a == 0
}
pub(crate) fn shader(&self) -> ShaderLight {
let light_type = match self.light_type {
LightType::Directional => 0,
LightType::Point => 1,
};
ShaderLight {
coords: self.coords,
color: Vec4::from(Rgbf::from(self.color)) * self.brightness,
light_type,
}
}
}