@@ -62,8 +62,8 @@ use bevy_render::{
6262 renderer:: { RenderContext , RenderDevice , RenderQueue , ViewQuery } ,
6363 settings:: WgpuFeatures ,
6464 view:: {
65- ExtractedView , NoIndirectDrawing , RenderVisibilityRanges , RetainedViewEntity , ViewUniform ,
66- ViewUniformOffset , ViewUniforms ,
65+ ExtractedView , NoIndirectDrawing , PointAndSpotLightShadowPrimaryCamera ,
66+ RenderVisibilityRanges , RetainedViewEntity , ViewUniform , ViewUniformOffset , ViewUniforms ,
6767 } ,
6868 GpuResourceAppExt , Render , RenderApp , RenderSystems ,
6969} ;
@@ -617,7 +617,13 @@ pub fn early_gpu_preprocess(
617617 ) ,
618618 Without < SkipGpuPreprocess > ,
619619 > ,
620- camera_views : Query < & ExtractedView , ( With < ExtractedCamera > , Without < SkipGpuPreprocess > ) > ,
620+ point_and_spot_light_shadow_primary_camera : Query <
621+ & ExtractedView ,
622+ (
623+ With < ExtractedCamera > ,
624+ With < PointAndSpotLightShadowPrimaryCamera > ,
625+ ) ,
626+ > ,
621627 view_query : Query <
622628 (
623629 & ExtractedView ,
@@ -650,6 +656,8 @@ pub fn early_gpu_preprocess(
650656 let ( shadow_cascade_views, extracted_view, has_non_root_view) = current_view. into_inner ( ) ;
651657 let all_views =
652658 gather_shadow_cascades_for_view ( view_entity, shadow_cascade_views, & light_query) ;
659+ let point_and_spot_light_shadow_camera_view =
660+ point_and_spot_light_shadow_primary_camera. single ( ) ;
653661
654662 // Run the compute passes.
655663 for view_entity in all_views {
@@ -668,16 +676,13 @@ pub fn early_gpu_preprocess(
668676 extracted_view. world_from_view . translation ( ) . to_array ( )
669677 } else {
670678 // PointLight and SpotLight shadow views are handled in this else block.
671- // TODO: We need to better handle this case.
672- // As written, point and spot lights shadow views will just use the first user camera
673- // that is returned by the query.
674- // If there is only one user camera, this is fine, but for multiple user cameras,
675- // only one of them is randomly used for visibility range culling.
676- let camera_view: Option < & ExtractedView > = camera_views. iter ( ) . next ( ) ;
677- if let Some ( camera_view) = camera_view {
679+ // We could handle this case better if we can specify certain point and spot light shadow
680+ // views to different cameras. Right now, it is all centralized to one user specified camera.
681+ if let Ok ( camera_view) = point_and_spot_light_shadow_camera_view {
678682 camera_view. world_from_view . translation ( ) . to_array ( )
679683 } else {
680- // No camera views to render to.
684+ // There is no single designated primary camera to use for vis range culling of the shadows.
685+ // Do not render them.
681686 continue ;
682687 }
683688 } ;
0 commit comments