gloss_renderer/components/
light_comps.rs

1// use gloss_hecs::Bundle;
2
3extern crate nalgebra as na;
4extern crate nalgebra_glm as glm;
5
6/// Component usually added on lights. Defines properties of the light emitter.
7pub struct LightEmit {
8    pub color: na::Vector3<f32>,
9    pub intensity: f32,
10    pub range: f32,
11    pub radius: f32, //Each spotlight is represented as a circle of this radius
12    //from Bevy https://github.com/bevyengine/bevy/blob/0cc11791b9a55f5d310ee754c9f7254081e7138a/crates/bevy_pbr/src/light.rs#L108
13    // More explained on filament in the SpotLight section https://google.github.io/filament/Filament.md.html
14    /// Angle defining the distance from the spot light direction to the outer
15    /// limit of the light's cone of effect.
16    /// `outer_angle` should be < `PI / 2.0`.
17    /// `PI / 2.0` defines a hemispherical spot light, but shadows become very
18    /// blocky as the angle approaches this limit.
19    pub outer_angle: f32,
20    /// Angle defining the distance from the spot light direction to the inner
21    /// limit of the light's cone of effect.
22    /// Light is attenuated from `inner_angle` to `outer_angle` to give a smooth
23    /// falloff. `inner_angle` should be <= `outer_angle`
24    pub inner_angle: f32,
25    // pub spot_scale: f32, //the spotlight can be made tigher or wider with this
26    //TODO width and height for area lights
27}
28impl Default for LightEmit {
29    fn default() -> LightEmit {
30        Self {
31            color: na::Vector3::<f32>::new(1.0, 1.0, 1.0),
32            intensity: 30.0,
33            range: 100.0,
34            radius: 0.1,
35            outer_angle: std::f32::consts::PI / 2.0, //correspond to a 180 hemisphere
36            inner_angle: 0.0,
37        }
38    }
39}
40
41/// Component added to a Light to indicate that it will cast a shadow with a
42/// certain resolution
43pub struct ShadowCaster {
44    /// Resolution of the shadow map. Shadow map is always a square texture.
45    pub shadow_res: u32,
46    pub shadow_bias_fixed: f32,
47    pub shadow_bias: f32,
48    pub shadow_bias_normal: f32,
49}
50impl Default for ShadowCaster {
51    fn default() -> Self {
52        Self {
53            shadow_res: 2048,
54            shadow_bias_fixed: 2e-6,
55            shadow_bias: 2e-6,
56            shadow_bias_normal: 2e-6,
57        }
58    }
59}
60
61/// Component that is usually automatically added by the renderer on all
62/// entities that have [`ShadowCaster`]
63pub struct ShadowMap {
64    pub tex_depth: easy_wgpu::texture::Texture,
65    // pub tex_depth_moments: easy_wgpu::texture::Texture,
66}
67
68// /so we can use the Components inside the Mutex<Hashmap> in the scene and wasm
69// https://stackoverflow.com/a/73773940/22166964
70// shenanigans
71//verts
72#[cfg(target_arch = "wasm32")]
73unsafe impl Send for ShadowMap {}
74#[cfg(target_arch = "wasm32")]
75unsafe impl Sync for ShadowMap {}