mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
29c632b524
commit
9b006fdf75
1 changed files with 8 additions and 7 deletions
|
@ -545,19 +545,20 @@ fn apply_pbr_lighting(
|
||||||
// example, both lightmaps and irradiance volumes are present.
|
// example, both lightmaps and irradiance volumes are present.
|
||||||
|
|
||||||
var indirect_light = vec3(0.0f);
|
var indirect_light = vec3(0.0f);
|
||||||
|
var found_diffuse_indirect = false;
|
||||||
|
|
||||||
#ifdef LIGHTMAP
|
#ifdef LIGHTMAP
|
||||||
if (all(indirect_light == vec3(0.0f))) {
|
indirect_light += in.lightmap_light * diffuse_color;
|
||||||
indirect_light += in.lightmap_light * diffuse_color;
|
found_diffuse_indirect = true;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IRRADIANCE_VOLUME {
|
#ifdef IRRADIANCE_VOLUME
|
||||||
// Irradiance volume light (indirect)
|
// Irradiance volume light (indirect)
|
||||||
if (all(indirect_light == vec3(0.0f))) {
|
if (!found_diffuse_indirect) {
|
||||||
let irradiance_volume_light = irradiance_volume::irradiance_volume_light(
|
let irradiance_volume_light = irradiance_volume::irradiance_volume_light(
|
||||||
in.world_position.xyz, in.N);
|
in.world_position.xyz, in.N);
|
||||||
indirect_light += irradiance_volume_light * diffuse_color * diffuse_occlusion;
|
indirect_light += irradiance_volume_light * diffuse_color * diffuse_occlusion;
|
||||||
|
found_diffuse_indirect = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -574,7 +575,7 @@ fn apply_pbr_lighting(
|
||||||
|
|
||||||
let environment_light = environment_map::environment_map_light(
|
let environment_light = environment_map::environment_map_light(
|
||||||
environment_map_lighting_input,
|
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
|
// 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) {
|
if (!use_ssr) {
|
||||||
let environment_light = environment_map::environment_map_light(
|
let environment_light = environment_map::environment_map_light(
|
||||||
&lighting_input,
|
&lighting_input,
|
||||||
any(indirect_light != vec3(0.0f))
|
found_diffuse_indirect
|
||||||
);
|
);
|
||||||
|
|
||||||
indirect_light += environment_light.diffuse * diffuse_occlusion +
|
indirect_light += environment_light.diffuse * diffuse_occlusion +
|
||||||
|
|
Loading…
Reference in a new issue