Skip to main content

oxide_engine/light/
components.rs

1//! Light component definitions
2
3use glam::Vec3;
4
5use oxide_ecs::Component;
6
7/// A directional light (like the sun) that affects all objects uniformly.
8#[derive(Component, Clone, Copy, Debug)]
9pub struct DirectionalLight {
10    /// Direction the light is pointing (should be normalized).
11    pub direction: Vec3,
12    /// RGB color of the light.
13    pub color: Vec3,
14    /// Light intensity multiplier.
15    pub intensity: f32,
16}
17
18impl Default for DirectionalLight {
19    fn default() -> Self {
20        Self {
21            direction: Vec3::NEG_Y,
22            color: Vec3::ONE,
23            intensity: 1.0,
24        }
25    }
26}
27
28impl DirectionalLight {
29    /// Creates a new directional light.
30    pub fn new(direction: Vec3, color: Vec3, intensity: f32) -> Self {
31        Self {
32            direction: direction.normalize(),
33            color,
34            intensity,
35        }
36    }
37}
38
39/// A point light that radiates from a position in all directions.
40#[derive(Component, Clone, Copy, Debug)]
41pub struct PointLight {
42    /// World position of the light.
43    pub position: Vec3,
44    /// RGB color of the light.
45    pub color: Vec3,
46    /// Light intensity multiplier.
47    pub intensity: f32,
48    /// Maximum distance the light affects (attenuation).
49    pub radius: f32,
50}
51
52impl Default for PointLight {
53    fn default() -> Self {
54        Self {
55            position: Vec3::ZERO,
56            color: Vec3::ONE,
57            intensity: 1.0,
58            radius: 10.0,
59        }
60    }
61}
62
63impl PointLight {
64    /// Creates a new point light.
65    pub fn new(position: Vec3, color: Vec3, intensity: f32, radius: f32) -> Self {
66        Self {
67            position,
68            color,
69            intensity,
70            radius,
71        }
72    }
73}
74
75/// Ambient lighting that affects all objects uniformly.
76/// Only one ambient light should be active at a time.
77#[derive(Component, Clone, Copy, Debug)]
78pub struct AmbientLight {
79    /// RGB color of the ambient light.
80    pub color: Vec3,
81    /// Light intensity multiplier.
82    pub intensity: f32,
83}
84
85impl Default for AmbientLight {
86    fn default() -> Self {
87        Self {
88            color: Vec3::ONE,
89            intensity: 0.2,
90        }
91    }
92}
93
94impl AmbientLight {
95    /// Creates a new ambient light.
96    pub fn new(color: Vec3, intensity: f32) -> Self {
97        Self { color, intensity }
98    }
99}