nightshade 0.13.3

A cross-platform data-oriented game engine.
Documentation
//! Light component definitions.

use serde::{Deserialize, Serialize};

/// Type of light source following glTF KHR_lights_punctual.
#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum LightType {
    /// Infinitely distant light (like the sun). Uses entity's -Z direction.
    #[default]
    Directional,
    /// Omnidirectional point light. Uses entity's position.
    Point,
    /// Cone-shaped spotlight. Uses entity's position and -Z direction.
    Spot,
}

/// Light source component.
///
/// Attach to an entity with a transform to illuminate the scene.
/// The transform's -Z axis defines the light direction (for directional and spot lights).
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Light {
    /// The type of light (directional, point, or spot).
    pub light_type: LightType,
    /// Light color as linear RGB.
    pub color: nalgebra_glm::Vec3,
    /// Light intensity (lumens for point/spot, lux for directional).
    pub intensity: f32,
    /// Maximum range for point/spot lights (0 = unlimited).
    pub range: f32,
    /// Inner cone angle in radians for spot lights (full intensity).
    pub inner_cone_angle: f32,
    /// Outer cone angle in radians for spot lights (zero intensity).
    pub outer_cone_angle: f32,
    /// Whether this light casts shadows.
    pub cast_shadows: bool,
    /// Depth bias to reduce shadow acne artifacts.
    pub shadow_bias: f32,
}

impl Light {
    /// Enables shadow casting with the specified depth bias.
    pub fn with_shadows(mut self, bias: f32) -> Self {
        self.cast_shadows = true;
        self.shadow_bias = bias;
        self
    }
}