bevy/crates/bevy_pbr/src
Martin Lysell b91a233acf
Fix AmbientLight::affects_lightmapped_meshes not working (#20083)
# Objective

Fix lightmapped materials not respecting the
AmbientLight::affects_lightmapped_meshes setting.

NOTE: This only makes the setting work on the forward renderer. Making
it work on the deferred renderer would probably require encoding more
information in the g-buffer or similar. Please advise if I missed some
obvious way to get it working on deferred.

## Solution

- Make ambient light conditionally applied depending on the
affects_lightmapped_meshes setting when material mesh i lightmapped
- Remove what looks to be leftover `Lights` (wgsl) members:
`environment_map_smallest_specular_mip_level`,
`environment_map_intensity`. (These where not present in the rust
equivalent `GpuLights` and was not used in the wgsl code)

## Open Questions
- Ambient light is also blended into the transmitted light if
`DIFFUSE_TRANSMISSION` is enabled on the material. Should that also be
guarded by the same conditional as the indirect contribution?

## Testing

Ran a modified version of the lightmaps example, where there is a bright
red ambient light added and the small cube do not have a lightmap added
(To be able to see ambient light applied to meshes without lightmaps)

---

## Showcase
### Main: Lightmap example with bright red ambient, small box have no
lightmap
<img width="613" height="601" alt="Main"
src="https://github.com/user-attachments/assets/a3f206d7-5a1e-4590-8c40-69d5c6e06ce0"
/>

(All meshes get ambient light even when `affects_lightmapped_meshes =
false`)

### This PR: Lightmap example with bright red ambient, small box have no
lightmap
<img width="612" height="602" alt="With fix"
src="https://github.com/user-attachments/assets/d1a149a5-8994-4572-909f-8788ba2c38fc"
/>

(Only the small box get ambient light when `affects_lightmapped_meshes =
false`)
2025-07-14 21:13:10 +00:00
..
atmosphere Make render and compute pipeline descriptors defaultable. (#19903) 2025-07-02 18:47:27 +00:00
decal bevy_light (#19991) 2025-07-07 00:07:38 +00:00
deferred Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
light_probe Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
lightmap Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
meshlet Clean up several miscellaneous uses of weak_handle. (#19408) 2025-07-08 06:45:40 +00:00
prepass Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
render Fix AmbientLight::affects_lightmapped_meshes not working (#20083) 2025-07-14 21:13:10 +00:00
ssao Make render and compute pipeline descriptors defaultable. (#19903) 2025-07-02 18:47:27 +00:00
ssr Make render and compute pipeline descriptors defaultable. (#19903) 2025-07-02 18:47:27 +00:00
volumetric_fog Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
cluster.rs bevy_light (#19991) 2025-07-07 00:07:38 +00:00
components.rs move some Visibility stuff to bevy_camera::visibility (#19954) 2025-07-05 13:24:20 +00:00
extended_material.rs Type erased materials (#19667) 2025-06-27 22:57:24 +00:00
fog.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lib.rs Move IrradianceVolume to bevy_light (#20000) 2025-07-07 20:11:43 +00:00
material_bind_groups.rs Type erased materials (#19667) 2025-06-27 22:57:24 +00:00
material.rs Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00
mesh_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
parallax.rs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
pbr_material.rs StandardMaterial docs: Make clear that lighting won't look correct if is_srgb is true (#20037) 2025-07-10 18:41:37 +00:00
wireframe.rs Use RenderStartup for bevy_pbr for some basic cases. (#19999) 2025-07-14 20:28:03 +00:00