use gfx;
use object;
use std::ops;
use camera::Orthographic;
use hub::Operation;
use render::{BackendResources, ShadowFormat};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ShadowMap {
pub(crate) resource: gfx::handle::ShaderResourceView<BackendResources, f32>,
pub(crate) target: gfx::handle::DepthStencilView<BackendResources, ShadowFormat>,
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum ShadowProjection {
Orthographic(Orthographic),
}
impl ShadowMap {
pub(crate) fn to_target(&self) -> gfx::handle::DepthStencilView<BackendResources, ShadowFormat> {
self.target.clone()
}
pub(crate) fn to_resource(&self) -> gfx::handle::ShaderResourceView<BackendResources, f32> {
self.resource.clone()
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Ambient {
pub(crate) object: object::Base,
}
three_object!(Ambient::object);
impl Ambient {
pub(crate) fn new(object: object::Base) -> Self {
Ambient { object }
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Directional {
pub(crate) object: object::Base,
pub(crate) shadow: Option<ShadowMap>,
}
three_object!(Directional::object);
impl Directional {
pub(crate) fn new(object: object::Base) -> Self {
Directional {
object,
shadow: None,
}
}
pub fn has_shadow(&self) -> bool {
self.shadow.is_some()
}
pub fn set_shadow(
&mut self,
map: ShadowMap,
extent_y: f32,
range: ops::Range<f32>,
) {
let sp = ShadowProjection::Orthographic(Orthographic {
center: [0.0; 2].into(),
extent_y,
range,
});
self.shadow = Some(map.clone());
let msg = Operation::SetShadow(map, sp);
let _ = self.object.tx.send((self.object.node.downgrade(), msg));
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Hemisphere {
pub(crate) object: object::Base,
}
three_object!(Hemisphere::object);
impl Hemisphere {
pub(crate) fn new(object: object::Base) -> Self {
Hemisphere { object }
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Point {
pub(crate) object: object::Base,
}
three_object!(Point::object);
impl Point {
pub(crate) fn new(object: object::Base) -> Self {
Point { object }
}
}