diff --git a/crates/bevy_pbr/src/deferred/pbr_deferred_functions.wgsl b/crates/bevy_pbr/src/deferred/pbr_deferred_functions.wgsl index b892181377..e96de6bded 100644 --- a/crates/bevy_pbr/src/deferred/pbr_deferred_functions.wgsl +++ b/crates/bevy_pbr/src/deferred/pbr_deferred_functions.wgsl @@ -53,6 +53,22 @@ fn deferred_gbuffer_from_pbr_input(in: PbrInput) -> vec4 { } else { base_color_srgb = pow(in.material.base_color.rgb, vec3(1.0 / 2.2)); } + + // Utilize the emissive channel to transmit the lightmap data. To ensure + // it matches the output in forward shading, pre-multiply it with the + // calculated diffuse color. + let base_color = in.material.base_color.rgb; + let metallic = in.material.metallic; + let specular_transmission = in.material.specular_transmission; + let diffuse_transmission = in.material.diffuse_transmission; + let diffuse_color = pbr_functions::calculate_diffuse_color( + base_color, + metallic, + specular_transmission, + diffuse_transmission + ); + emissive += in.lightmap_light * diffuse_color * view.exposure; + let deferred = vec4( deferred_types::pack_unorm4x8_(vec4(base_color_srgb, in.material.perceptual_roughness)), rgb9e5::vec3_to_rgb9e5_(emissive), diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index bcaef63068..39de9d029a 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -429,6 +429,10 @@ where shader_defs.push("DEFERRED_PREPASS".into()); } + if key.mesh_key.contains(MeshPipelineKey::LIGHTMAPPED) { + shader_defs.push("LIGHTMAP".into()); + } + if layout.0.contains(Mesh::ATTRIBUTE_COLOR) { shader_defs.push("VERTEX_COLORS".into()); vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(7));