From 7883eea54f70d6b7cda5bc9f101bf61bbf0aab2c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 16 Feb 2024 16:25:32 -0800 Subject: [PATCH] Add `MeshPipelineKey::LIGHTMAPPED` as applicable during the shadow map pass. (#11910) I did this during the prepass, but I neglected to do it during the shadow map pass, causing a panic when directional lights with shadows were enabled with lightmapped meshes present. This patch fixes the issue. Closes #11898. --- crates/bevy_pbr/src/render/light.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index d97ab7a5cd..e57dd38f4a 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1596,6 +1596,7 @@ pub fn queue_shadows( render_material_instances: Res>, mut pipelines: ResMut>>, pipeline_cache: Res, + render_lightmaps: Res, view_lights: Query<(Entity, &ViewLightEntities)>, mut view_light_shadow_phases: Query<(&LightEntity, &mut RenderPhase)>, point_light_entities: Query<&CubemapVisibleEntities, With>, @@ -1661,6 +1662,16 @@ pub fn queue_shadows( if is_directional_light { mesh_key |= MeshPipelineKey::DEPTH_CLAMP_ORTHO; } + + // Even though we don't use the lightmap in the shadow map, the + // `SetMeshBindGroup` render command will bind the data for it. So + // we need to include the appropriate flag in the mesh pipeline key + // to ensure that the necessary bind group layout entries are + // present. + if render_lightmaps.render_lightmaps.contains_key(&entity) { + mesh_key |= MeshPipelineKey::LIGHTMAPPED; + } + mesh_key |= match material.properties.alpha_mode { AlphaMode::Mask(_) | AlphaMode::Blend