MAJOR rendering overhaul. Snow deformation, persistent light, flowmap out. Also ECS architexture overhaul
This commit is contained in:
@@ -12,7 +12,7 @@ struct AccumulationUniforms
|
||||
delta_time: f32,
|
||||
spotlight_count: u32,
|
||||
_padding: u32,
|
||||
light_view_projection: [[f32; 4]; 4],
|
||||
light_view_projections: [[[f32; 4]; 4]; crate::render::MAX_SPOTLIGHTS],
|
||||
shadow_bias: f32,
|
||||
terrain_height_scale: f32,
|
||||
_padding3: f32,
|
||||
@@ -48,12 +48,8 @@ pub struct SnowLightAccumulation
|
||||
|
||||
impl SnowLightAccumulation
|
||||
{
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
terrain_min: Vec2,
|
||||
terrain_max: Vec2,
|
||||
resolution: u32,
|
||||
) -> Self
|
||||
pub fn new(device: &wgpu::Device, terrain_min: Vec2, terrain_max: Vec2, resolution: u32)
|
||||
-> Self
|
||||
{
|
||||
let size = wgpu::Extent3d {
|
||||
width: resolution,
|
||||
@@ -68,8 +64,7 @@ impl SnowLightAccumulation
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::R16Float,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
};
|
||||
|
||||
@@ -145,7 +140,7 @@ impl SnowLightAccumulation
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
sample_type: wgpu::TextureSampleType::Depth,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
view_dimension: wgpu::TextureViewDimension::D2Array,
|
||||
multisampled: false,
|
||||
},
|
||||
count: None,
|
||||
@@ -232,9 +227,7 @@ impl SnowLightAccumulation
|
||||
});
|
||||
|
||||
let vertices: &[f32] = &[
|
||||
-1.0, -1.0, 0.0, 1.0,
|
||||
3.0, -1.0, 2.0, 1.0,
|
||||
-1.0, 3.0, 0.0, -1.0,
|
||||
-1.0, -1.0, 0.0, 1.0, 3.0, -1.0, 2.0, 1.0, -1.0, 3.0, 0.0, -1.0,
|
||||
];
|
||||
|
||||
let quad_vb = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
@@ -419,7 +412,7 @@ impl SnowLightAccumulation
|
||||
queue: &wgpu::Queue,
|
||||
spotlights: &[crate::render::Spotlight],
|
||||
delta_time: f32,
|
||||
light_view_projection: &glam::Mat4,
|
||||
light_view_projections: &[glam::Mat4],
|
||||
shadow_bias: f32,
|
||||
terrain_height_scale: f32,
|
||||
)
|
||||
@@ -430,8 +423,12 @@ impl SnowLightAccumulation
|
||||
self.needs_clear = false;
|
||||
}
|
||||
|
||||
let mut spotlight_array = [crate::render::SpotlightRaw::default(); crate::render::MAX_SPOTLIGHTS];
|
||||
for (i, spotlight) in spotlights.iter().take(crate::render::MAX_SPOTLIGHTS).enumerate()
|
||||
let mut spotlight_array =
|
||||
[crate::render::SpotlightRaw::default(); crate::render::MAX_SPOTLIGHTS];
|
||||
for (i, spotlight) in spotlights
|
||||
.iter()
|
||||
.take(crate::render::MAX_SPOTLIGHTS)
|
||||
.enumerate()
|
||||
{
|
||||
spotlight_array[i] = spotlight.to_raw();
|
||||
}
|
||||
@@ -443,7 +440,17 @@ impl SnowLightAccumulation
|
||||
delta_time,
|
||||
spotlight_count: spotlights.len().min(crate::render::MAX_SPOTLIGHTS) as u32,
|
||||
_padding: 0,
|
||||
light_view_projection: light_view_projection.to_cols_array_2d(),
|
||||
light_view_projections: {
|
||||
let mut arr = [[[0.0f32; 4]; 4]; crate::render::MAX_SPOTLIGHTS];
|
||||
for (i, mat) in light_view_projections
|
||||
.iter()
|
||||
.take(crate::render::MAX_SPOTLIGHTS)
|
||||
.enumerate()
|
||||
{
|
||||
arr[i] = mat.to_cols_array_2d();
|
||||
}
|
||||
arr
|
||||
},
|
||||
shadow_bias,
|
||||
terrain_height_scale,
|
||||
_padding3: 0.0,
|
||||
@@ -453,10 +460,26 @@ impl SnowLightAccumulation
|
||||
|
||||
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms]));
|
||||
|
||||
let write_view = if self.current { &self.view_ping } else { &self.view_pong };
|
||||
let bind_group = if self.current { self.bind_group_ping.as_ref() } else { self.bind_group_pong.as_ref() };
|
||||
let write_view = if self.current
|
||||
{
|
||||
&self.view_ping
|
||||
}
|
||||
else
|
||||
{
|
||||
&self.view_pong
|
||||
};
|
||||
let bind_group = if self.current
|
||||
{
|
||||
self.bind_group_ping.as_ref()
|
||||
}
|
||||
else
|
||||
{
|
||||
self.bind_group_pong.as_ref()
|
||||
};
|
||||
|
||||
let Some(bind_group) = bind_group else {
|
||||
let Some(bind_group) = bind_group
|
||||
else
|
||||
{
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -489,7 +512,14 @@ impl SnowLightAccumulation
|
||||
|
||||
pub fn read_view(&self) -> &wgpu::TextureView
|
||||
{
|
||||
if self.current { &self.view_pong } else { &self.view_ping }
|
||||
if self.current
|
||||
{
|
||||
&self.view_pong
|
||||
}
|
||||
else
|
||||
{
|
||||
&self.view_ping
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout
|
||||
|
||||
Reference in New Issue
Block a user