mod ambient;
mod directional;
mod hemisphere;
mod point;
mod rect_area;
pub(crate) mod shadow;
mod spot;
pub use ambient::AmbientLight;
pub use directional::DirectionalLight;
pub use hemisphere::HemisphereLight;
pub use point::PointLight;
pub use rect_area::RectAreaLight;
pub use shadow::{ShadowSettings, ShadowType};
pub use spot::SpotLight;
use crate::math::Color;
#[derive(Debug, Clone)]
pub enum Light {
Ambient(AmbientLight),
Directional(DirectionalLight),
Point(PointLight),
Spot(SpotLight),
Hemisphere(HemisphereLight),
RectArea(RectAreaLight),
}
impl Light {
pub fn color(&self) -> Color {
match self {
Light::Ambient(l) => l.color,
Light::Directional(l) => l.color,
Light::Point(l) => l.color,
Light::Spot(l) => l.color,
Light::Hemisphere(l) => l.sky_color,
Light::RectArea(l) => l.color,
}
}
pub fn intensity(&self) -> f32 {
match self {
Light::Ambient(l) => l.intensity,
Light::Directional(l) => l.intensity,
Light::Point(l) => l.intensity,
Light::Spot(l) => l.intensity,
Light::Hemisphere(l) => l.intensity,
Light::RectArea(l) => l.intensity,
}
}
pub fn set_color(&mut self, color: Color) {
match self {
Light::Ambient(l) => l.color = color,
Light::Directional(l) => l.color = color,
Light::Point(l) => l.color = color,
Light::Spot(l) => l.color = color,
Light::Hemisphere(l) => l.sky_color = color,
Light::RectArea(l) => l.color = color,
}
}
pub fn set_intensity(&mut self, intensity: f32) {
match self {
Light::Ambient(l) => l.intensity = intensity,
Light::Directional(l) => l.intensity = intensity,
Light::Point(l) => l.intensity = intensity,
Light::Spot(l) => l.intensity = intensity,
Light::Hemisphere(l) => l.intensity = intensity,
Light::RectArea(l) => l.intensity = intensity,
}
}
}
impl From<AmbientLight> for Light {
fn from(l: AmbientLight) -> Self {
Light::Ambient(l)
}
}
impl From<DirectionalLight> for Light {
fn from(l: DirectionalLight) -> Self {
Light::Directional(l)
}
}
impl From<PointLight> for Light {
fn from(l: PointLight) -> Self {
Light::Point(l)
}
}
impl From<SpotLight> for Light {
fn from(l: SpotLight) -> Self {
Light::Spot(l)
}
}
impl From<HemisphereLight> for Light {
fn from(l: HemisphereLight) -> Self {
Light::Hemisphere(l)
}
}
impl From<RectAreaLight> for Light {
fn from(l: RectAreaLight) -> Self {
Light::RectArea(l)
}
}