Skip to content

Commit 9b006fd

Browse files
authored
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.
1 parent 29c632b commit 9b006fd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

crates/bevy_pbr/src/render/pbr_functions.wgsl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,20 @@ fn apply_pbr_lighting(
545545
// example, both lightmaps and irradiance volumes are present.
546546

547547
var indirect_light = vec3(0.0f);
548+
var found_diffuse_indirect = false;
548549

549550
#ifdef LIGHTMAP
550-
if (all(indirect_light == vec3(0.0f))) {
551-
indirect_light += in.lightmap_light * diffuse_color;
552-
}
551+
indirect_light += in.lightmap_light * diffuse_color;
552+
found_diffuse_indirect = true;
553553
#endif
554554

555-
#ifdef IRRADIANCE_VOLUME {
555+
#ifdef IRRADIANCE_VOLUME
556556
// Irradiance volume light (indirect)
557-
if (all(indirect_light == vec3(0.0f))) {
557+
if (!found_diffuse_indirect) {
558558
let irradiance_volume_light = irradiance_volume::irradiance_volume_light(
559559
in.world_position.xyz, in.N);
560560
indirect_light += irradiance_volume_light * diffuse_color * diffuse_occlusion;
561+
found_diffuse_indirect = true;
561562
}
562563
#endif
563564

@@ -574,7 +575,7 @@ fn apply_pbr_lighting(
574575

575576
let environment_light = environment_map::environment_map_light(
576577
environment_map_lighting_input,
577-
any(indirect_light != vec3(0.0f))
578+
found_diffuse_indirect
578579
);
579580

580581
// If screen space reflections are going to be used for this material, don't
@@ -589,7 +590,7 @@ fn apply_pbr_lighting(
589590
if (!use_ssr) {
590591
let environment_light = environment_map::environment_map_light(
591592
&lighting_input,
592-
any(indirect_light != vec3(0.0f))
593+
found_diffuse_indirect
593594
);
594595

595596
indirect_light += environment_light.diffuse * diffuse_occlusion +

0 commit comments

Comments
 (0)