bevy_pbr: Make choosing of diffuse indirect lighting explicit. (#15093)

# Objective

Make choosing of diffuse indirect lighting explicit, instead of using
numerical conditions like `all(indirect_light == vec3(0.0f))`, as using
that may lead to unwanted light leakage.

## Solution

Use an explicit `found_diffuse_indirect` condition to indicate the found
indirect lighting source.

## Testing

I have tested examples `lightmaps`, `irradiance_volumes` and
`reflection_probes`, there are no visual changes. For further testing,
consider a "cave" scene with lightmaps and irradiance volumes. In the
cave there are some purly dark occluded area, those dark area will
sample the irradiance volume, and that is easy to leak light.
This commit is contained in:
研究社交 2024-09-10 00:11:16 +08:00 committed by GitHub
parent 29c632b524
commit 9b006fdf75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -545,19 +545,20 @@ fn apply_pbr_lighting(
// example, both lightmaps and irradiance volumes are present.
var indirect_light = vec3(0.0f);
var found_diffuse_indirect = false;
#ifdef LIGHTMAP
if (all(indirect_light == vec3(0.0f))) {
indirect_light += in.lightmap_light * diffuse_color;
}
found_diffuse_indirect = true;
#endif
#ifdef IRRADIANCE_VOLUME {
#ifdef IRRADIANCE_VOLUME
// Irradiance volume light (indirect)
if (all(indirect_light == vec3(0.0f))) {
if (!found_diffuse_indirect) {
let irradiance_volume_light = irradiance_volume::irradiance_volume_light(
in.world_position.xyz, in.N);
indirect_light += irradiance_volume_light * diffuse_color * diffuse_occlusion;
found_diffuse_indirect = true;
}
#endif
@ -574,7 +575,7 @@ fn apply_pbr_lighting(
let environment_light = environment_map::environment_map_light(
environment_map_lighting_input,
any(indirect_light != vec3(0.0f))
found_diffuse_indirect
);
// If screen space reflections are going to be used for this material, don't
@ -589,7 +590,7 @@ fn apply_pbr_lighting(
if (!use_ssr) {
let environment_light = environment_map::environment_map_light(
&lighting_input,
any(indirect_light != vec3(0.0f))
found_diffuse_indirect
);
indirect_light += environment_light.diffuse * diffuse_occlusion +