pub(crate) mod directional;
pub(crate) mod local;
pub(crate) mod traced;
use crate::settings::ShadowQuality;
use crate::view::bindings::ShadowMaps;
use crate::view::frame::FrameContext;
pub(crate) struct Shadows {
pub directional: directional::Directional,
pub local: local::Local,
sampler: wgpu::Sampler,
}
impl Shadows {
pub fn new(device: &wgpu::Device, quality: ShadowQuality) -> Self {
Self {
directional: directional::Directional::new(device, quality.cascade_size()),
local: local::Local::new(device, quality.atlas_size()),
sampler: device.create_sampler(&wgpu::SamplerDescriptor {
label: Some("shadow comparison"),
compare: Some(wgpu::CompareFunction::GreaterEqual),
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
..Default::default()
}),
}
}
pub fn resize(&mut self, device: &wgpu::Device, quality: ShadowQuality) {
if self.directional.size() != quality.cascade_size() {
self.directional = directional::Directional::new(device, quality.cascade_size());
}
self.local.resize(device, quality.atlas_size());
}
pub fn maps(&self) -> ShadowMaps {
ShadowMaps {
directional: self.directional.array.clone(),
local_atlas: self.local.atlas().clone(),
local_layers: self.local.layers().clone(),
local_records: self.local.records.clone(),
sampler: self.sampler.clone(),
}
}
pub fn encode_directional(&self, ctx: &mut FrameContext<'_>) {
self.directional.encode(ctx);
}
pub fn encode_local(&mut self, ctx: &mut FrameContext<'_>) {
self.local.encode(ctx);
}
}