use gfx;
use amethyst_assets::{PrefabData, PrefabError, ProgressCounter};
use amethyst_core::specs::prelude::{Component, DenseVecStorage, Entity, WriteStorage};
use crate::{color::Rgba, resources::AmbientColor};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, PrefabData)]
#[prefab(Component)]
pub enum Light {
Area,
Directional(DirectionalLight),
Point(PointLight),
Spot(SpotLight),
Sun(SunLight),
}
#[repr(C)]
#[derive(Clone, ConstantBuffer, Debug, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct DirectionalLight {
pub color: Rgba,
pub direction: [f32; 3], }
impl Default for DirectionalLight {
fn default() -> Self {
DirectionalLight {
color: Rgba::default(),
direction: [-1.0, -1.0, -1.0],
}
}
}
impl From<DirectionalLight> for Light {
fn from(dir: DirectionalLight) -> Self {
Light::Directional(dir)
}
}
#[repr(C)]
#[derive(Clone, ConstantBuffer, Debug, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct PointLight {
pub color: Rgba,
pub intensity: f32,
pub radius: f32,
pub smoothness: f32,
}
impl Default for PointLight {
fn default() -> Self {
PointLight {
color: Rgba::default(),
intensity: 10.0,
radius: 10.0,
smoothness: 4.0,
}
}
}
impl From<PointLight> for Light {
fn from(pt: PointLight) -> Self {
Light::Point(pt)
}
}
#[repr(C)]
#[derive(Clone, ConstantBuffer, Debug, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct SpotLight {
pub angle: f32,
pub color: Rgba,
pub direction: [f32; 3], pub intensity: f32,
pub range: f32,
pub smoothness: f32,
}
impl Default for SpotLight {
fn default() -> Self {
SpotLight {
angle: std::f32::consts::FRAC_PI_3,
color: Rgba::default(),
direction: [0.0, -1.0, 0.0],
intensity: 10.0,
range: 10.0,
smoothness: 4.0,
}
}
}
impl From<SpotLight> for Light {
fn from(sp: SpotLight) -> Self {
Light::Spot(sp)
}
}
#[repr(C)]
#[derive(Clone, ConstantBuffer, Debug, Deserialize, PartialEq, Serialize)]
#[serde(default)]
pub struct SunLight {
pub ang_rad: f32,
pub color: Rgba,
pub direction: [f32; 3], pub intensity: f32,
}
impl Default for SunLight {
fn default() -> Self {
SunLight {
ang_rad: 0.0093_f32.to_radians(),
color: Rgba::default(),
direction: [-1.0, -1.0, -1.0],
intensity: 64_000.0,
}
}
}
impl From<SunLight> for Light {
fn from(sun: SunLight) -> Self {
Light::Sun(sun)
}
}
impl Component for Light {
type Storage = DenseVecStorage<Self>;
}
#[derive(Default, Clone, Serialize, Deserialize, PrefabData)]
#[serde(default)]
pub struct LightPrefab {
light: Option<Light>,
ambient_color: Option<AmbientColor>,
}