From b225d523838af85dc7141f9c672fcf51177c2366 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Mar 2024 13:18:20 -0700 Subject: [PATCH 1/9] Divide the single `VisibleEntities` list into separate lists for 2D meshes, 3D meshes, and lights, for performance. This commit splits `VisibleEntities::entities` into three separate lists: one for lights, one for 2D meshes, and one for 3D meshes. This allows `queue_material_meshes` and similar methods to avoid examining entities that are obviously irrelevant. In particular, this separation helps scenes with many skinned meshes, as the individual bones are considered visible entities but have no rendered appearance. Internally, `VisibleEntities::entities` is a `HashMap` from the `TypeId` representing a `QueryFilter` to the appropriate `Entity` list. I had to do this because `VisibleEntities` is located within an upstream crate from the crates that provide lights (`bevy_pbr`) and 2D meshes (`bevy_sprite`). As an added benefit, this setup allows apps to provide their own types of renderable components, by simply adding a specialized `check_visibility` to the schedule. Currently, this provides minimal performance benefit in `many_foxes`, but on top of binning (#12453) it provides a 20% end-to-end speedup on that benchmark. * `check_visibility` and `VisibleEntities` now store the three types of renderable entities--2D meshes, 3D meshes, and lights--separately. If your custom rendering code examines `VisibleEntities`, it will now need to specify which type of entity it's interested in using the `WithMesh2d`, `WithMesh`, and `WithLight` types respectively. If your app introduces a new type of renderable entity, you'll need to add an explicit call to `check_visibility` to the schedule to accommodate your new component or components. --- crates/bevy_pbr/src/lib.rs | 10 +- crates/bevy_pbr/src/light/mod.rs | 18 ++-- crates/bevy_pbr/src/material.rs | 4 +- crates/bevy_pbr/src/prepass/mod.rs | 3 +- crates/bevy_pbr/src/render/light.rs | 4 +- crates/bevy_render/src/view/visibility/mod.rs | 99 ++++++++++++++----- crates/bevy_sprite/src/lib.rs | 11 ++- crates/bevy_sprite/src/mesh2d/material.rs | 4 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 4 + crates/bevy_sprite/src/render/mod.rs | 5 +- examples/2d/mesh2d_manual.rs | 4 +- 11 files changed, 121 insertions(+), 45 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index c969db7944c08..5d7591101d4cd 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -80,7 +80,7 @@ use bevy_render::{ render_phase::sort_phase_system, render_resource::Shader, texture::Image, - view::VisibilitySystems, + view::{check_visibility, VisibilitySystems}, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_transform::TransformSystem; @@ -311,6 +311,14 @@ impl Plugin for PbrPlugin { .in_set(SimulationLightSystems::UpdateLightFrusta) .after(TransformSystem::TransformPropagate) .after(SimulationLightSystems::AssignLightsToClusters), + check_visibility:: + .in_set(VisibilitySystems::CheckVisibility) + .after(VisibilitySystems::CalculateBounds) + .after(VisibilitySystems::UpdateOrthographicFrusta) + .after(VisibilitySystems::UpdatePerspectiveFrusta) + .after(VisibilitySystems::UpdateProjectionFrusta) + .after(VisibilitySystems::VisibilityPropagate) + .after(TransformSystem::TransformPropagate), check_light_mesh_visibility .in_set(SimulationLightSystems::CheckLightVisibility) .after(VisibilitySystems::CalculateBounds) diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 5d6be4fcf48d3..61f5d0de02cdf 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -13,7 +13,7 @@ use bevy_render::{ primitives::{Aabb, CascadesFrusta, CubemapFrusta, Frustum, HalfSpace, Sphere}, render_resource::BufferBindingType, renderer::RenderDevice, - view::{InheritedVisibility, RenderLayers, ViewVisibility, VisibleEntities}, + view::{InheritedVisibility, RenderLayers, ViewVisibility, VisibleEntities, WithMesh}, }; use bevy_transform::components::{GlobalTransform, Transform}; use bevy_utils::tracing::warn; @@ -285,6 +285,10 @@ impl DirectionalLight { pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; } +/// A convenient alias for `Or<(With, With, +/// With)>`, for use with [`VisibleEntities`]. +pub type WithLight = Or<(With, With, With)>; + /// Controls the resolution of [`DirectionalLight`] shadow maps. #[derive(Resource, Clone, Debug, Reflect)] #[reflect(Resource)] @@ -2127,7 +2131,7 @@ pub fn check_light_mesh_visibility( } view_visibility.set(); - frustum_visible_entities.entities.push(entity); + frustum_visible_entities.get_mut::().push(entity); } } } else { @@ -2139,7 +2143,7 @@ pub fn check_light_mesh_visibility( .expect("Per-view visible entities should have been inserted already"); for frustum_visible_entities in view_visible_entities { - frustum_visible_entities.entities.push(entity); + frustum_visible_entities.get_mut::().push(entity); } } } @@ -2208,13 +2212,13 @@ pub fn check_light_mesh_visibility( { if frustum.intersects_obb(aabb, &model_to_world, true, true) { view_visibility.set(); - visible_entities.entities.push(entity); + visible_entities.push::(entity); } } } else { view_visibility.set(); for visible_entities in cubemap_visible_entities.iter_mut() { - visible_entities.entities.push(entity); + visible_entities.push::(entity); } } } @@ -2269,11 +2273,11 @@ pub fn check_light_mesh_visibility( if frustum.intersects_obb(aabb, &model_to_world, true, true) { view_visibility.set(); - visible_entities.entities.push(entity); + visible_entities.push::(entity); } } else { view_visibility.set(); - visible_entities.entities.push(entity); + visible_entities.push::(entity); } } diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 96c32bfd6834c..13e6f4de16122 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -24,7 +24,7 @@ use bevy_render::{ render_resource::*, renderer::RenderDevice, texture::FallbackImage, - view::{ExtractedView, Msaa, VisibleEntities}, + view::{ExtractedView, Msaa, VisibleEntities, WithMesh}, Extract, }; use bevy_utils::{tracing::error, HashMap, HashSet}; @@ -598,7 +598,7 @@ pub fn queue_material_meshes( } let rangefinder = view.rangefinder3d(); - for visible_entity in &visible_entities.entities { + for visible_entity in visible_entities.iter::() { let Some(material_asset_id) = render_material_instances.get(visible_entity) else { continue; }; diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index f8d9ecc18808c..837d52452ba9d 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -2,6 +2,7 @@ mod prepass_bindings; use bevy_render::mesh::MeshVertexBufferLayoutRef; use bevy_render::render_resource::binding_types::uniform_buffer; +use bevy_render::view::WithMesh; pub use prepass_bindings::*; use bevy_asset::{load_internal_asset, AssetServer}; @@ -756,7 +757,7 @@ pub fn queue_prepass_material_meshes( view_key |= MeshPipelineKey::MOTION_VECTOR_PREPASS; } - for visible_entity in &visible_entities.entities { + for visible_entity in visible_entities.iter::() { let Some(material_asset_id) = render_material_instances.get(visible_entity) else { continue; }; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 12d8961f988a4..f75100e574b76 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -13,7 +13,7 @@ use bevy_render::{ render_resource::*, renderer::{RenderContext, RenderDevice, RenderQueue}, texture::*, - view::{ExtractedView, RenderLayers, ViewVisibility, VisibleEntities}, + view::{ExtractedView, RenderLayers, ViewVisibility, VisibleEntities, WithMesh}, Extract, }; use bevy_transform::{components::GlobalTransform, prelude::Transform}; @@ -1643,7 +1643,7 @@ pub fn queue_shadows( }; // NOTE: Lights with shadow mapping disabled will have no visible entities // so no meshes will be queued - for entity in visible_entities.iter().copied() { + for entity in visible_entities.iter::().copied() { let Some(mesh_instance) = render_mesh_instances.get(&entity) else { continue; }; diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index c674a36829e05..b300daca8fe05 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -1,6 +1,9 @@ mod render_layers; +use std::any::TypeId; + use bevy_derive::Deref; +use bevy_ecs::query::QueryFilter; pub use render_layers::*; use bevy_app::{Plugin, PostUpdate}; @@ -9,7 +12,7 @@ use bevy_ecs::prelude::*; use bevy_hierarchy::{Children, Parent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_transform::{components::GlobalTransform, TransformSystem}; -use bevy_utils::Parallel; +use bevy_utils::{HashMap, Parallel}; use crate::deterministic::DeterministicRenderingConfig; use crate::{ @@ -171,23 +174,67 @@ pub struct NoFrustumCulling; #[reflect(Component)] pub struct VisibleEntities { #[reflect(ignore)] - pub entities: Vec, + pub entities: HashMap>, } impl VisibleEntities { - pub fn iter(&self) -> impl DoubleEndedIterator { - self.entities.iter() + pub fn get(&self) -> &[Entity] + where + QF: 'static, + { + match self.entities.get(&TypeId::of::()) { + Some(entities) => &entities[..], + None => &[], + } + } + + pub fn get_mut(&mut self) -> &mut Vec + where + QF: 'static, + { + self.entities.entry(TypeId::of::()).or_default() + } + + pub fn iter(&self) -> impl DoubleEndedIterator + where + QF: 'static, + { + self.get::().iter() + } + + pub fn len(&self) -> usize + where + QF: 'static, + { + self.get::().len() } - pub fn len(&self) -> usize { - self.entities.len() + pub fn is_empty(&self) -> bool + where + QF: 'static, + { + self.get::().is_empty() } - pub fn is_empty(&self) -> bool { - self.entities.is_empty() + pub fn clear(&mut self) + where + QF: 'static, + { + self.get_mut::().clear(); + } + + pub fn push(&mut self, entity: Entity) + where + QF: 'static, + { + self.get_mut::().push(entity); } } +/// A convenient alias for `With>`, for use with +/// [`VisibleEntities`]. +pub type WithMesh = With>; + #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] pub enum VisibilitySystems { /// Label for the [`calculate_bounds`], `calculate_bounds_2d` and `calculate_bounds_text2d` systems, @@ -239,7 +286,7 @@ impl Plugin for VisibilityPlugin { .after(camera_system::) .after(TransformSystem::TransformPropagate), (visibility_propagate_system, reset_view_visibility).in_set(VisibilityPropagate), - check_visibility + check_visibility:: .in_set(CheckVisibility) .after(CalculateBounds) .after(UpdateOrthographicFrusta) @@ -370,7 +417,7 @@ fn reset_view_visibility(mut query: Query<&mut ViewVisibility>) { /// The system is part of the [`VisibilitySystems::CheckVisibility`] set. Each frame, it updates the /// [`ViewVisibility`] of all entities, and for each view also compute the [`VisibleEntities`] /// for that view. -pub fn check_visibility( +pub fn check_visibility( mut thread_queues: Local>>, mut view_query: Query<( &mut VisibleEntities, @@ -378,17 +425,22 @@ pub fn check_visibility( Option<&RenderLayers>, &Camera, )>, - mut visible_aabb_query: Query<( - Entity, - &InheritedVisibility, - &mut ViewVisibility, - Option<&RenderLayers>, - Option<&Aabb>, - &GlobalTransform, - Has, - )>, + mut visible_aabb_query: Query< + ( + Entity, + &InheritedVisibility, + &mut ViewVisibility, + Option<&RenderLayers>, + Option<&Aabb>, + &GlobalTransform, + Has, + ), + QF, + >, deterministic_rendering_config: Res, -) { +) where + QF: QueryFilter + 'static, +{ for (mut visible_entities, frustum, maybe_view_mask, camera) in &mut view_query { if !camera.is_active { continue; @@ -396,7 +448,6 @@ pub fn check_visibility( let view_mask = maybe_view_mask.copied().unwrap_or_default(); - visible_entities.entities.clear(); visible_aabb_query.par_iter_mut().for_each(|query_item| { let ( entity, @@ -444,12 +495,12 @@ pub fn check_visibility( }); }); - visible_entities.entities.clear(); - thread_queues.drain_into(&mut visible_entities.entities); + visible_entities.clear::(); + thread_queues.drain_into(visible_entities.get_mut::()); if deterministic_rendering_config.stable_sort_z_fighting { // We can use the faster unstable sort here because // the values (`Entity`) are guaranteed to be unique. - visible_entities.entities.sort_unstable(); + visible_entities.get_mut::().sort_unstable(); } } } diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index 685ecb0d4b54a..b0dcc59335e1e 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -26,6 +26,7 @@ pub mod prelude { }; } +use bevy_transform::TransformSystem; pub use bundle::*; pub use dynamic_texture_atlas_builder::*; pub use mesh2d::*; @@ -45,7 +46,7 @@ use bevy_render::{ render_phase::AddRenderCommand, render_resource::{Shader, SpecializedRenderPipelines}, texture::Image, - view::{NoFrustumCulling, VisibilitySystems}, + view::{check_visibility, NoFrustumCulling, VisibilitySystems}, ExtractSchedule, Render, RenderApp, RenderSet, }; @@ -88,6 +89,14 @@ impl Plugin for SpritePlugin { compute_slices_on_sprite_change, ) .in_set(SpriteSystem::ComputeSlices), + check_visibility:: + .in_set(VisibilitySystems::CheckVisibility) + .after(VisibilitySystems::CalculateBounds) + .after(VisibilitySystems::UpdateOrthographicFrusta) + .after(VisibilitySystems::UpdatePerspectiveFrusta) + .after(VisibilitySystems::UpdateProjectionFrusta) + .after(VisibilitySystems::VisibilityPropagate) + .after(TransformSystem::TransformPropagate), ), ); diff --git a/crates/bevy_sprite/src/mesh2d/material.rs b/crates/bevy_sprite/src/mesh2d/material.rs index 0b4a7be28c669..94f119a2d7ea2 100644 --- a/crates/bevy_sprite/src/mesh2d/material.rs +++ b/crates/bevy_sprite/src/mesh2d/material.rs @@ -36,7 +36,7 @@ use std::marker::PhantomData; use crate::{ DrawMesh2d, Mesh2dHandle, Mesh2dPipeline, Mesh2dPipelineKey, RenderMesh2dInstances, - SetMesh2dBindGroup, SetMesh2dViewBindGroup, + SetMesh2dBindGroup, SetMesh2dViewBindGroup, WithMesh2d, }; /// Materials are used alongside [`Material2dPlugin`] and [`MaterialMesh2dBundle`] @@ -411,7 +411,7 @@ pub fn queue_material2d_meshes( view_key |= Mesh2dPipelineKey::DEBAND_DITHER; } } - for visible_entity in &visible_entities.entities { + for visible_entity in visible_entities.iter::() { let Some(material_asset_id) = render_material_instances.get(visible_entity) else { continue; }; diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 5cd5fcb894374..1d0fdd9834cda 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -48,6 +48,10 @@ impl From> for Mesh2dHandle { } } +/// A convenient alias for `With`, for use with +/// [`bevy_render::view::VisibleEntities`]. +pub type WithMesh2d = With; + #[derive(Default)] pub struct Mesh2dRenderPlugin; diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 00cb03febad18..a82282f32411e 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -1,8 +1,7 @@ use std::ops::Range; use crate::{ - texture_atlas::{TextureAtlas, TextureAtlasLayout}, - ComputedTextureSlices, Sprite, SPRITE_SHADER_HANDLE, + texture_atlas::{TextureAtlas, TextureAtlasLayout}, ComputedTextureSlices, Sprite, WithMesh2d, SPRITE_SHADER_HANDLE }; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; use bevy_color::LinearRgba; @@ -507,7 +506,7 @@ pub fn queue_sprites( ); view_entities.clear(); - view_entities.extend(visible_entities.entities.iter().map(|e| e.index() as usize)); + view_entities.extend(visible_entities.iter::().map(|e| e.index() as usize)); transparent_phase .items diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index acb0d3b6dce85..62029207bfb87 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -26,7 +26,7 @@ use bevy::{ sprite::{ extract_mesh2d, DrawMesh2d, Material2dBindGroupId, Mesh2dHandle, Mesh2dPipeline, Mesh2dPipelineKey, Mesh2dTransforms, MeshFlags, RenderMesh2dInstance, - RenderMesh2dInstances, SetMesh2dBindGroup, SetMesh2dViewBindGroup, + RenderMesh2dInstances, SetMesh2dBindGroup, SetMesh2dViewBindGroup, WithMesh2d, }, utils::FloatOrd, }; @@ -362,7 +362,7 @@ pub fn queue_colored_mesh2d( | Mesh2dPipelineKey::from_hdr(view.hdr); // Queue all entities visible to that view - for visible_entity in &visible_entities.entities { + for visible_entity in visible_entities.iter::() { if let Some(mesh_instance) = render_mesh_instances.get(visible_entity) { let mesh2d_handle = mesh_instance.mesh_asset_id; let mesh2d_transforms = &mesh_instance.transforms; From a6ffc08d0de104c12a7e7a15a085f378e9d9117b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Mar 2024 21:43:33 -0700 Subject: [PATCH 2/9] Rustfmt police --- crates/bevy_sprite/src/render/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index a82282f32411e..f3990de4bc32d 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -1,7 +1,8 @@ use std::ops::Range; use crate::{ - texture_atlas::{TextureAtlas, TextureAtlasLayout}, ComputedTextureSlices, Sprite, WithMesh2d, SPRITE_SHADER_HANDLE + texture_atlas::{TextureAtlas, TextureAtlasLayout}, + ComputedTextureSlices, Sprite, WithMesh2d, SPRITE_SHADER_HANDLE, }; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; use bevy_color::LinearRgba; @@ -506,7 +507,11 @@ pub fn queue_sprites( ); view_entities.clear(); - view_entities.extend(visible_entities.iter::().map(|e| e.index() as usize)); + view_entities.extend( + visible_entities + .iter::() + .map(|e| e.index() as usize), + ); transparent_phase .items From 3cbb44adec17e477dde728556ede7e60fb733d0c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Mar 2024 00:59:54 -0700 Subject: [PATCH 3/9] Add UI elements to `VisibleEntities` --- crates/bevy_ui/src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 2ec6b130350c6..341003b7e7f34 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -49,7 +49,10 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_ecs::prelude::*; use bevy_input::InputSystem; -use bevy_render::RenderApp; +use bevy_render::{ + view::{check_visibility, VisibilitySystems}, + RenderApp, +}; use bevy_transform::TransformSystem; use stack::ui_stack_system; pub use stack::UiStack; @@ -93,6 +96,9 @@ struct AmbiguousWithTextSystem; #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] struct AmbiguousWithUpdateText2DLayout; +/// A convenient alias for `With`, for use with [`VisibleEntities`]. +pub type WithNode = With; + impl Plugin for UiPlugin { fn build(&self, app: &mut App) { app.init_resource::() @@ -125,6 +131,13 @@ impl Plugin for UiPlugin { app.add_systems( PostUpdate, ( + check_visibility:: + .in_set(VisibilitySystems::CheckVisibility) + .after(VisibilitySystems::CalculateBounds) + .after(VisibilitySystems::UpdateOrthographicFrusta) + .after(VisibilitySystems::UpdatePerspectiveFrusta) + .after(VisibilitySystems::UpdateProjectionFrusta) + .after(VisibilitySystems::VisibilityPropagate), update_target_camera_system.before(UiSystem::Layout), apply_deferred .after(update_target_camera_system) From aeee61823d851f77c840e5e40ac744b4da9a62e1 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Mar 2024 15:43:32 -0700 Subject: [PATCH 4/9] Doc check police --- crates/bevy_ui/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 341003b7e7f34..75072b168332c 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -96,7 +96,8 @@ struct AmbiguousWithTextSystem; #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] struct AmbiguousWithUpdateText2DLayout; -/// A convenient alias for `With`, for use with [`VisibleEntities`]. +/// A convenient alias for `With`, for use with +/// [`bevy_render::view::VisibleEntities`]. pub type WithNode = With; impl Plugin for UiPlugin { From 253cb253b3ba78c699eb1b9a040c206dd707d34b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 30 Mar 2024 17:21:26 -0700 Subject: [PATCH 5/9] Only check meshes for light visibility --- crates/bevy_pbr/src/light/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index eecfde351d4fa..fc33ad7279fd1 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -10,6 +10,7 @@ use bevy_render::{ camera::{Camera, CameraProjection}, extract_component::ExtractComponent, extract_resource::ExtractResource, + mesh::Mesh, primitives::{Aabb, CascadesFrusta, CubemapFrusta, Frustum, HalfSpace, Sphere}, render_resource::BufferBindingType, renderer::RenderDevice, @@ -98,7 +99,6 @@ impl Default for PointLightShadowMap { } } - /// A convenient alias for `Or<(With, With, /// With)>`, for use with [`VisibleEntities`]. pub type WithLight = Or<(With, With, With)>; @@ -1857,7 +1857,11 @@ pub fn check_light_mesh_visibility( Option<&Aabb>, Option<&GlobalTransform>, ), - (Without, Without), + ( + Without, + Without, + With>, + ), >, ) { fn shrink_entities(visible_entities: &mut VisibleEntities) { From 2e40d1e9a80b44a9e1107633aa0c3f4327c3b626 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 31 Mar 2024 11:32:14 -0700 Subject: [PATCH 6/9] Doc check police --- crates/bevy_pbr/src/light/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index fc33ad7279fd1..ac3e2948c53b2 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -437,11 +437,11 @@ fn calculate_cascade( texel_size: cascade_texel_size, } } -/// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. +/// Add this component to make a [`Mesh`] not cast shadows. #[derive(Component, Reflect, Default)] #[reflect(Component, Default)] pub struct NotShadowCaster; -/// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not receive shadows. +/// Add this component to make a [`Mesh`] not receive shadows. /// /// **Note:** If you're using diffuse transmission, setting [`NotShadowReceiver`] will /// cause both “regular” shadows as well as diffusely transmitted shadows to be disabled, @@ -449,7 +449,7 @@ pub struct NotShadowCaster; #[derive(Component, Reflect, Default)] #[reflect(Component, Default)] pub struct NotShadowReceiver; -/// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0` +/// Add this component to make a [`Mesh`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0` /// receive shadows on its diffuse transmission lobe. (i.e. its “backside”) /// /// Not enabled by default, as it requires carefully setting up [`thickness`](crate::pbr_material::StandardMaterial::thickness) From 1a60ba82268717fd28cbe446201766d5db47037d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 1 Apr 2024 13:13:24 -0700 Subject: [PATCH 7/9] Use `TypeIdMap` --- crates/bevy_render/src/view/visibility/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index cbcdc6aeb1557..3ffa1aa49c620 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -12,7 +12,7 @@ use bevy_ecs::prelude::*; use bevy_hierarchy::{Children, Parent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_transform::{components::GlobalTransform, TransformSystem}; -use bevy_utils::{HashMap, Parallel}; +use bevy_utils::{Parallel, TypeIdMap}; use crate::deterministic::DeterministicRenderingConfig; use crate::{ @@ -174,7 +174,7 @@ pub struct NoFrustumCulling; #[reflect(Component, Default)] pub struct VisibleEntities { #[reflect(ignore)] - pub entities: HashMap>, + pub entities: TypeIdMap>, } impl VisibleEntities { From deb3de4a300815ae8247af02b0e03d350aa37702 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 11 Apr 2024 12:32:45 -0700 Subject: [PATCH 8/9] Add more documentation to `check_visibility`. --- crates/bevy_render/src/view/visibility/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index bf65f762652b6..878470fe05efe 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -413,9 +413,14 @@ fn reset_view_visibility(mut query: Query<&mut ViewVisibility>) { /// System updating the visibility of entities each frame. /// -/// The system is part of the [`VisibilitySystems::CheckVisibility`] set. Each frame, it updates the -/// [`ViewVisibility`] of all entities, and for each view also compute the [`VisibleEntities`] -/// for that view. +/// The system is part of the [`VisibilitySystems::CheckVisibility`] set. Each +/// frame, it updates the [`ViewVisibility`] of all entities, and for each view +/// also compute the [`VisibleEntities`] for that view. +/// +/// This system needs to be run for each type of renderable entity. If you add a +/// new type of renderable entity, you'll need to add an instantiation of this +/// system to the [`CheckVisibility`] set so that Bevy will detect visibility +/// properly for those entities. pub fn check_visibility( mut thread_queues: Local>>, mut view_query: Query<( From 626fba38fb25f02a2d32dde1a16f00d54ec6ded3 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 11 Apr 2024 12:57:04 -0700 Subject: [PATCH 9/9] Doc check police --- crates/bevy_render/src/view/visibility/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 878470fe05efe..9418f7847a7d1 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -419,8 +419,8 @@ fn reset_view_visibility(mut query: Query<&mut ViewVisibility>) { /// /// This system needs to be run for each type of renderable entity. If you add a /// new type of renderable entity, you'll need to add an instantiation of this -/// system to the [`CheckVisibility`] set so that Bevy will detect visibility -/// properly for those entities. +/// system to the [`VisibilitySystems::CheckVisibility`] set so that Bevy will +/// detect visibility properly for those entities. pub fn check_visibility( mut thread_queues: Local>>, mut view_query: Query<(