Skip to content

Commit

Permalink
Merge pull request #38 from ForesightMiningSoftwareCorporation/fix-sh…
Browse files Browse the repository at this point in the history
…adows
  • Loading branch information
IceSentry authored Nov 5, 2023
2 parents ce802e5 + 9ff886e commit 9f59085
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ fn extract_infinite_grids(

fn extract_grid_shadows(
mut commands: Commands,
grids: Extract<Query<(Entity, &ExtractedInfiniteGrid, &GridFrustumIntersect)>>,
grids: Extract<Query<(Entity, &InfiniteGridSettings, &GridFrustumIntersect)>>,
) {
let extracted: Vec<_> = grids
.iter()
.filter(|(_, extracted, _)| extracted.grid.shadow_color.is_some())
.filter(|(_, grid_settings, _)| grid_settings.shadow_color.is_some())
.map(|(entity, _, intersect)| (entity, (*intersect,)))
.collect();
commands.insert_or_spawn_batch(extracted);
Expand Down
26 changes: 14 additions & 12 deletions src/render/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use bevy::{
renderer::RenderDevice,
texture::TextureCache,
view::{
ExtractedView, ExtractedWindows, ViewUniform, ViewUniformOffset, ViewUniforms,
VisibleEntities,
prepare_view_uniforms, ExtractedView, ExtractedWindows, ViewUniform, ViewUniformOffset,
ViewUniforms, VisibleEntities,
},
Render, RenderApp, RenderSet,
},
Expand Down Expand Up @@ -439,10 +439,15 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetGridShadowBindGroup<I
}
}

#[allow(clippy::type_complexity)]
struct GridShadowPassNode {
grids: Vec<Entity>,
grid_entity_query: QueryState<Entity, With<GridShadowView>>,
grid_element_query: QueryState<(Read<GridShadowView>, Read<RenderPhase<GridShadow>>)>,
grid_element_query: QueryState<(
Read<GridShadowView>,
Read<RenderPhase<GridShadow>>,
Read<ViewUniformOffset>,
)>,
}

impl GridShadowPassNode {
Expand Down Expand Up @@ -471,7 +476,7 @@ impl Node for GridShadowPassNode {
world: &World,
) -> Result<(), bevy::render::render_graph::NodeRunError> {
for &entity in &self.grids {
let (shadow_view, render_phase) =
let (shadow_view, render_phase, _) =
self.grid_element_query.get_manual(world, entity).unwrap();
let pass_descriptor = RenderPassDescriptor {
label: Some("grid_shadow_pass"),
Expand All @@ -486,13 +491,8 @@ impl Node for GridShadowPassNode {
depth_stencil_attachment: None,
};

let draw_functions = world.resource::<DrawFunctions<GridShadow>>();
let mut tracked_render_pass = render_context.begin_tracked_render_pass(pass_descriptor);
let mut draw_functions = draw_functions.write();
for item in &render_phase.items {
let draw_function = draw_functions.get_mut(item.draw_function).unwrap();
draw_function.draw(world, &mut tracked_render_pass, entity, item);
}
render_phase.render(&mut tracked_render_pass, world, entity);
}

Ok(())
Expand Down Expand Up @@ -534,8 +534,10 @@ pub fn register_shadow(app: &mut App) {
.add_render_command::<GridShadow, DrawGridShadowMesh>()
.add_systems(
Render,
// Register as exclusive system because ordering against `bevy_render::view::prepare_view_uniforms` isn't possible otherwise.
prepare_grid_shadow_views.in_set(RenderSet::Prepare),
(prepare_grid_shadow_views, apply_deferred)
.chain()
.before(prepare_view_uniforms)
.in_set(RenderSet::Prepare),
)
.add_systems(
Render,
Expand Down

0 comments on commit 9f59085

Please sign in to comment.