diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 5cdea0627b7b7..380eb87bbfde0 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1830,6 +1830,8 @@ pub fn specialize_shadows( pub fn queue_shadows( shadow_draw_functions: Res>, render_mesh_instances: Res, + render_materials: Res>>, + render_material_instances: Res>, mut shadow_render_phases: ResMut>, gpu_preprocessing_support: Res, mesh_allocator: Res, @@ -1900,12 +1902,20 @@ pub fn queue_shadows( continue; } + let Some(material_asset_id) = render_material_instances.get(&main_entity) else { + continue; + }; + let Some(material) = render_materials.get(*material_asset_id) else { + continue; + }; + let (vertex_slab, index_slab) = mesh_allocator.mesh_slabs(&mesh_instance.mesh_asset_id); let batch_set_key = ShadowBatchSetKey { pipeline: *pipeline_id, draw_function: draw_shadow_mesh, + material_bind_group_index: Some(material.binding.group.0), vertex_slab: vertex_slab.unwrap_or_default(), index_slab, }; @@ -1952,6 +1962,11 @@ pub struct ShadowBatchSetKey { /// The function used to draw. pub draw_function: DrawFunctionId, + /// The ID of a bind group specific to the material. + /// + /// In the case of PBR, this is the `MaterialBindGroupIndex`. + pub material_bind_group_index: Option, + /// The ID of the slab of GPU memory that contains vertex data. /// /// For non-mesh items, you can fill this with 0 if your items can be