Made directed shadows take advantage of culling

This commit is contained in:
Joshua Barretto 2023-02-09 22:22:13 +00:00
parent de1c961141
commit 4699569eae
3 changed files with 35 additions and 14 deletions

View File

@ -794,11 +794,24 @@ impl<'pass_ref, 'pass: 'pass_ref> TerrainShadowDrawer<'pass_ref, 'pass> {
&mut self,
model: &'data Model<terrain::Vertex>,
locals: &'data terrain::BoundLocals,
alt_indices: &'data crate::scene::terrain::AltIndices,
is_underground: bool,
) {
// Don't render anything if there's nothing to render!
if is_underground || alt_indices.deep_end == model.len() {
return;
}
let submodel = if is_underground {
model.submodel(0..alt_indices.underground_end as u32)
} else {
model.submodel(alt_indices.deep_end as u32..model.len() as u32)
};
self.render_pass.set_bind_group(1, &locals.bind_group, &[]);
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
self.render_pass.set_vertex_buffer(0, submodel.buf());
self.render_pass
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
.draw_indexed(0..submodel.len() / 4 * 6, 0, 0..1);
}
}

View File

@ -1262,8 +1262,11 @@ impl Scene {
prof_span!("directed shadows");
if let Some(mut shadow_pass) = drawer.shadow_pass() {
// Render terrain directed shadows.
self.terrain
.render_shadows(&mut shadow_pass.draw_terrain_shadows(), focus_pos);
self.terrain.render_shadows(
&mut shadow_pass.draw_terrain_shadows(),
focus_pos,
is_underground,
);
// Render figure directed shadows.
self.figure_mgr.render_shadows(

View File

@ -1536,6 +1536,7 @@ impl<V: RectRasterableVol> Terrain<V> {
&'a self,
drawer: &mut TerrainShadowDrawer<'_, 'a>,
focus_pos: Vec3<f32>,
is_underground: bool,
) {
span!(_guard, "render_shadows", "Terrain::render_shadows");
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
@ -1558,12 +1559,15 @@ impl<V: RectRasterableVol> Terrain<V> {
.filter(|chunk| chunk.can_shadow_sun())
.chain(self.shadow_chunks.iter().map(|(_, chunk)| chunk))
.filter_map(|chunk| {
chunk
.opaque_model
.as_ref()
.map(|model| (model, &chunk.locals))
Some((
chunk.opaque_model.as_ref()?,
&chunk.locals,
&chunk.alt_indices,
))
})
.for_each(|(model, locals)| drawer.draw(model, locals));
.for_each(|(model, locals, alt_indices)| {
drawer.draw(model, locals, alt_indices, is_underground)
});
}
pub fn render_rain_occlusion<'a>(
@ -1585,13 +1589,14 @@ impl<V: RectRasterableVol> Terrain<V> {
chunk_iter
// Find a way to keep this?
// .filter(|chunk| chunk.can_shadow_sun())
.filter_map(|chunk| {
.filter_map(|chunk| Some((
chunk
.opaque_model
.as_ref()
.map(|model| (model, &chunk.locals))
})
.for_each(|(model, locals)| drawer.draw(model, locals));
.as_ref()?,
&chunk.locals,
&chunk.alt_indices,
)))
.for_each(|(model, locals, alt_indices)| drawer.draw(model, locals, alt_indices, false));
}
pub fn chunks_for_point_shadows(