Fix: EEVEE-Next: Lightprobe: Avoid division by zero

The normalization factor can divide by zero. Add a small
bias to avoid this. Since the bias is the same on both
the numerator and the denominator, the result converges
to 1 as the denominator reaches zero.

This also adds a `saturate` to avoid lighting being
weirdly increase in some part of the volume probe.

Fix #119799
This commit is contained in:
Clément Foucault
2024-04-23 20:27:05 +02:00
parent 29c3997c28
commit dc20def2f9

View File

@@ -28,6 +28,8 @@ ReflectionProbeLowFreqLight reflection_probes_extract_low_freq(SphericalHarmonic
/* To avoid color shift and negative values, we reduce saturation and directionality. */
ReflectionProbeLowFreqLight result;
result.ambient = sh.L0.M0.r + sh.L0.M0.g + sh.L0.M0.b;
/* Bias to avoid division by zero. */
result.ambient += 1e-6f;
mat3x4 L1_per_band;
L1_per_band[0] = sh.L1.Mn1;
@@ -46,5 +48,5 @@ float reflection_probes_normalization_eval(vec3 L,
{
/* TODO(fclem): Adjusting directionality is tricky.
* Needs to be revisited later on. For now only use the ambient term. */
return (numerator.ambient * safe_rcp(denominator.ambient));
return saturate(numerator.ambient / denominator.ambient);
}