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