@@ -448,7 +448,7 @@ pub fn extract_lights(
448
448
point_light_shadow_map : Res < PointLightShadowMap > ,
449
449
directional_light_shadow_map : Res < DirectionalLightShadowMap > ,
450
450
global_point_lights : Res < VisiblePointLights > ,
451
- // visible_point_lights: Query<&VisiblePointLights >,
451
+ mut previous_point_lights_len : Local < usize > ,
452
452
mut point_lights : Query < ( & PointLight , & mut CubemapVisibleEntities , & GlobalTransform ) > ,
453
453
mut directional_lights : Query < (
454
454
Entity ,
@@ -474,32 +474,38 @@ pub fn extract_lights(
474
474
// https://catlikecoding.com/unity/tutorials/custom-srp/point-and-spot-shadows/
475
475
let point_light_texel_size = 2.0 / point_light_shadow_map. size as f32 ;
476
476
477
+ let mut point_lights_values = Vec :: with_capacity ( * previous_point_lights_len) ;
477
478
for entity in global_point_lights. iter ( ) . copied ( ) {
478
479
if let Ok ( ( point_light, cubemap_visible_entities, transform) ) = point_lights. get_mut ( entity)
479
480
{
480
481
let render_cubemap_visible_entities =
481
482
std:: mem:: take ( cubemap_visible_entities. into_inner ( ) ) ;
482
- commands. get_or_spawn ( entity) . insert_bundle ( (
483
- ExtractedPointLight {
484
- color : point_light. color ,
485
- // NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
486
- // for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
487
- // for details.
488
- intensity : point_light. intensity / ( 4.0 * std:: f32:: consts:: PI ) ,
489
- range : point_light. range ,
490
- radius : point_light. radius ,
491
- transform : * transform,
492
- shadows_enabled : point_light. shadows_enabled ,
493
- shadow_depth_bias : point_light. shadow_depth_bias ,
494
- // The factor of SQRT_2 is for the worst-case diagonal offset
495
- shadow_normal_bias : point_light. shadow_normal_bias
496
- * point_light_texel_size
497
- * std:: f32:: consts:: SQRT_2 ,
498
- } ,
499
- render_cubemap_visible_entities,
483
+ point_lights_values. push ( (
484
+ entity,
485
+ (
486
+ ExtractedPointLight {
487
+ color : point_light. color ,
488
+ // NOTE: Map from luminous power in lumens to luminous intensity in lumens per steradian
489
+ // for a point light. See https://google.github.io/filament/Filament.html#mjx-eqn-pointLightLuminousPower
490
+ // for details.
491
+ intensity : point_light. intensity / ( 4.0 * std:: f32:: consts:: PI ) ,
492
+ range : point_light. range ,
493
+ radius : point_light. radius ,
494
+ transform : * transform,
495
+ shadows_enabled : point_light. shadows_enabled ,
496
+ shadow_depth_bias : point_light. shadow_depth_bias ,
497
+ // The factor of SQRT_2 is for the worst-case diagonal offset
498
+ shadow_normal_bias : point_light. shadow_normal_bias
499
+ * point_light_texel_size
500
+ * std:: f32:: consts:: SQRT_2 ,
501
+ } ,
502
+ render_cubemap_visible_entities,
503
+ ) ,
500
504
) ) ;
501
505
}
502
506
}
507
+ * previous_point_lights_len = point_lights_values. len ( ) ;
508
+ commands. insert_or_spawn_batch ( point_lights_values) ;
503
509
504
510
for ( entity, directional_light, visible_entities, transform) in directional_lights. iter_mut ( ) {
505
511
// Calulate the directional light shadow map texel size using the largest x,y dimension of
0 commit comments