diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index b018103afc6c5..1fb16580e862c 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -390,19 +390,10 @@ pub fn check_visibility( &InheritedVisibility, &mut ViewVisibility, Option<&RenderLayers>, - &Aabb, + Option<&Aabb>, &GlobalTransform, Has, )>, - mut visible_no_aabb_query: Query< - ( - Entity, - &InheritedVisibility, - &mut ViewVisibility, - Option<&RenderLayers>, - ), - Without, - >, ) { for (mut visible_entities, frustum, maybe_view_mask) in &mut view_query { let view_mask = maybe_view_mask.copied().unwrap_or_default(); @@ -414,7 +405,7 @@ pub fn check_visibility( inherited_visibility, mut view_visibility, maybe_entity_mask, - model_aabb, + maybe_model_aabb, transform, no_frustum_culling, ) = query_item; @@ -430,20 +421,22 @@ pub fn check_visibility( return; } - // If we have an aabb and transform, do frustum culling + // If we have an aabb, do frustum culling if !no_frustum_culling { - let model = transform.affine(); - let model_sphere = Sphere { - center: model.transform_point3a(model_aabb.center), - radius: transform.radius_vec3a(model_aabb.half_extents), - }; - // Do quick sphere-based frustum culling - if !frustum.intersects_sphere(&model_sphere, false) { - return; - } - // If we have an aabb, do aabb-based frustum culling - if !frustum.intersects_obb(model_aabb, &model, true, false) { - return; + if let Some(model_aabb) = maybe_model_aabb { + let model = transform.affine(); + let model_sphere = Sphere { + center: model.transform_point3a(model_aabb.center), + radius: transform.radius_vec3a(model_aabb.half_extents), + }; + // Do quick sphere-based frustum culling + if !frustum.intersects_sphere(&model_sphere, false) { + return; + } + // Do aabb-based frustum culling + if !frustum.intersects_obb(model_aabb, &model, true, false) { + return; + } } } @@ -454,27 +447,6 @@ pub fn check_visibility( cell.set(queue); }); - visible_no_aabb_query.par_iter_mut().for_each(|query_item| { - let (entity, inherited_visibility, mut view_visibility, maybe_entity_mask) = query_item; - - // Skip computing visibility for entities that are configured to be hidden. - // `ViewVisibility` has already been reset in `reset_view_visibility`. - if !inherited_visibility.get() { - return; - } - - let entity_mask = maybe_entity_mask.copied().unwrap_or_default(); - if !view_mask.intersects(&entity_mask) { - return; - } - - view_visibility.set(); - let cell = thread_queues.get_or_default(); - let mut queue = cell.take(); - queue.push(entity); - cell.set(queue); - }); - for cell in &mut thread_queues { visible_entities.entities.append(cell.get_mut()); }