gizmo_renderer/components/
light.rs1use gizmo_math::Vec3;
2
3#[derive(Clone, Copy, serde::Serialize, serde::Deserialize)]
4pub struct PointLight {
5 pub color: Vec3,
6 pub intensity: f32,
7 pub radius: f32,
8}
9
10impl PointLight {
11 pub fn new(color: Vec3, intensity: f32, radius: f32) -> Self {
12 let intensity = intensity.max(0.0);
13 let radius = radius.max(0.001);
14 Self {
15 color,
16 intensity,
17 radius,
18 }
19 }
20}
21
22#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
23pub enum LightRole {
24 Sun,
25 Generic,
26}
27
28#[derive(Clone, Copy, serde::Serialize, serde::Deserialize)]
29pub struct DirectionalLight {
30 pub color: Vec3,
31 pub intensity: f32,
32 pub role: LightRole,
33}
34
35impl DirectionalLight {
36 pub fn new(color: Vec3, intensity: f32, role: LightRole) -> Self {
37 let intensity = intensity.max(0.0);
38 Self {
39 color,
40 intensity,
41 role,
42 }
43 }
44}
45
46#[derive(Clone, Copy, serde::Serialize, serde::Deserialize)]
47pub struct SpotLight {
48 pub color: Vec3,
49 pub intensity: f32,
50 pub radius: f32,
51 pub inner_angle: f32,
52 pub outer_angle: f32,
53}
54
55impl SpotLight {
56 pub fn new(
57 color: Vec3,
58 intensity: f32,
59 radius: f32,
60 inner_angle: f32,
61 outer_angle: f32,
62 ) -> Self {
63 let intensity = intensity.max(0.0);
64 let radius = radius.max(0.001);
65 let inner_angle = inner_angle.min(outer_angle);
66 Self {
67 color,
68 intensity,
69 radius,
70 inner_angle,
71 outer_angle,
72 }
73 }
74}