Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opting-out of check_visibility system and creation of their own #17189

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ pub enum VisibilitySystems {
/// the order of systems within this set is irrelevant, as [`check_visibility`]
/// assumes that its operations are irreversible during the frame.
CheckVisibility,
/// Label for systems which do their own custom visibility checking.
CustomCheckVisibility,
}

pub struct VisibilityPlugin;
Expand All @@ -336,9 +338,14 @@ impl Plugin for VisibilityPlugin {
app.register_type::<VisibilityClass>()
.configure_sets(
PostUpdate,
(CalculateBounds, UpdateFrusta, VisibilityPropagate)
.before(CheckVisibility)
.after(TransformSystem::TransformPropagate),
(
(CalculateBounds, UpdateFrusta, VisibilityPropagate)
.before(CheckVisibility)
.after(TransformSystem::TransformPropagate),
CustomCheckVisibility
.in_set(CheckVisibility)
.after(check_visibility),
),
)
.init_resource::<PreviousVisibleEntities>()
.add_systems(
Expand Down Expand Up @@ -463,7 +470,7 @@ pub struct PreviousVisibleEntities(EntityHashSet);
/// Entities that are visible will be marked as such later this frame
/// by a [`VisibilitySystems::CheckVisibility`] system.
fn reset_view_visibility(
mut query: Query<(Entity, &ViewVisibility)>,
mut query: Query<(Entity, &ViewVisibility), Without<CustomVisibilityCheck>>,
mut previous_visible_entities: ResMut<PreviousVisibleEntities>,
) {
previous_visible_entities.clear();
Expand All @@ -476,6 +483,10 @@ fn reset_view_visibility(
});
}

/// Entities with this marker won't get their visibility checked and if they aren't using custom checking/rendering then won't be rendered.
#[derive(Debug, Component)]
pub struct CustomVisibilityCheck;

/// System updating the visibility of entities each frame.
///
/// The system is part of the [`VisibilitySystems::CheckVisibility`] set. Each
Expand All @@ -494,17 +505,20 @@ pub fn check_visibility(
&Camera,
Has<NoCpuCulling>,
)>,
mut visible_aabb_query: Query<(
Entity,
&InheritedVisibility,
&mut ViewVisibility,
&VisibilityClass,
Option<&RenderLayers>,
Option<&Aabb>,
&GlobalTransform,
Has<NoFrustumCulling>,
Has<VisibilityRange>,
)>,
mut visible_aabb_query: Query<
(
Entity,
&InheritedVisibility,
&mut ViewVisibility,
&VisibilityClass,
Option<&RenderLayers>,
Option<&Aabb>,
&GlobalTransform,
Has<NoFrustumCulling>,
Has<VisibilityRange>,
),
Without<CustomVisibilityCheck>,
>,
visible_entity_ranges: Option<Res<VisibleEntityRanges>>,
mut previous_visible_entities: ResMut<PreviousVisibleEntities>,
) {
Expand Down
Loading