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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
use crate::builder;
use crate::color::{Color, Rgb};
use crate::data_types::vector::Vec3;
use crate::ecs::Component;
use crate::reflection::Reflection;
builder! {
#[builder(name = PointLightBuilder, derives = (Debug, Clone))]
#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct PointLight
{
/// Position in local space.
pub local_position: Vec3<f32>,
pub diffuse: Color<f32>,
pub specular: Color<f32>,
pub attenuation_params: AttenuationParams,
}
}
impl PointLight
{
#[must_use]
pub fn builder() -> PointLightBuilder
{
PointLightBuilder::default()
}
}
impl Default for PointLight
{
fn default() -> Self
{
Self {
local_position: Vec3::default(),
diffuse: Color::Rgb(Rgb { r: 0.5, g: 0.5, b: 0.5 }),
specular: Color::Rgb(Rgb::<f32>::white()),
attenuation_params: AttenuationParams::default(),
}
}
}
impl Default for PointLightBuilder
{
fn default() -> Self
{
PointLight::default().into()
}
}
/// Parameters for light [attenuation](https://en.wikipedia.org/wiki/Attenuation).
#[derive(Debug, Clone, Reflection)]
pub struct AttenuationParams
{
pub constant: f32,
pub linear: f32,
pub quadratic: f32,
}
impl Default for AttenuationParams
{
fn default() -> Self
{
Self {
constant: 1.0,
linear: 0.0,
quadratic: 0.0,
}
}
}
builder! {
#[builder(name = DirectionalLightBuilder, derives = (Debug, Clone))]
#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct DirectionalLight
{
pub diffuse: Color<f32>,
pub specular: Color<f32>,
pub direction: Vec3<f32>,
}
}
impl DirectionalLight
{
#[must_use]
pub fn builder() -> DirectionalLightBuilder
{
DirectionalLightBuilder::default()
}
}
impl Default for DirectionalLight
{
fn default() -> Self
{
Self::builder().build()
}
}
impl Default for DirectionalLightBuilder
{
fn default() -> Self
{
Self {
diffuse: Color::Rgb(Rgb { r: 0.5, g: 0.5, b: 0.5 }),
specular: Color::Rgb(Rgb::<f32>::white()),
direction: Vec3::LEFT,
}
}
}
builder! {
#[builder(name = EnvironmentalBuilder, derives = (Debug, Clone))]
#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct Environmental
{
pub ambient_color: Color<f32>,
}
}
impl Environmental
{
pub fn builder() -> EnvironmentalBuilder
{
EnvironmentalBuilder::default()
}
}
impl Default for Environmental
{
fn default() -> Self
{
Self::builder().build()
}
}
impl Default for EnvironmentalBuilder
{
fn default() -> Self
{
Self {
ambient_color: Color::Rgb(Rgb { r: 0.2, g: 0.2, b: 0.2 }),
}
}
}
|