1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
use std::mem::{self, Discriminant}; #[derive(Component, Clone, Copy, PartialEq, Debug, Serialize, Deserialize)] pub enum Type{ PCSS, Poisson{ soft_scatter: f32 }, Gaussian, Hard, } impl Type{ pub fn to_str(&self) -> &'static str{ match self{ Type::PCSS => "SHADOW_MAP_PCSS", Type::Poisson{..} => "SHADOW_MAP_POISON_DISK", Type::Gaussian => "SHADOW_MAP_GAUSSIAN", Type::Hard => "SHADOW_MAP_HARD", } } pub fn discriminant_to_str(ty: Discriminant<Type>) -> &'static str{ if ty == mem::discriminant(&Type::PCSS) { "SHADOW_MAP_PCSS" } else if ty == mem::discriminant(&Type::Poisson{soft_scatter: 0.}) { "SHADOW_MAP_POISON_DISK" } else if ty == mem::discriminant(&Type::Gaussian) { "SHADOW_MAP_GAUSSIAN" } else if ty == mem::discriminant(&Type::Hard) { "SHADOW_MAP_HARD" } else { unreachable!() } } } #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum Resolution{ _16, _24, _32, } #[derive(Clone, Copy, Component, Debug, Serialize, Deserialize)] pub struct Parameters{ pub map_size: u16, pub resolution: Resolution, pub frustum_size: f32, pub near_clip: f32, pub far_clip: f32, pub bias: f32, } #[derive(Component, Debug, Serialize, Deserialize)] pub struct Map(pub(crate) Parameters); impl Map{ pub fn parameters(&self) -> &Parameters{ &self.0 } } #[derive(Component, Debug, Serialize, Deserialize)] pub struct StaticMap(pub(crate) Parameters); impl StaticMap{ pub fn parameters(&self) -> &Parameters{ &self.0 } }