EEVEE-Next: Fix World Reflection During Raytracing

Scenes that only uses a world probe would didn't work. Raytracing
would look for the closest light probe, didn't find any and shader
would use undefined behavior to sample in the reflectionProbes texture.

In some cases this resulted in correct results when the world was
located on layer 0 with subdivision 0. In any other case this would
sample incorrect incoming light what lead to black reflections.

This PR fixes this by returning the world probe when no nearest light
probe cound be found.

Pull Request: https://projects.blender.org/blender/blender/pulls/112893
This commit is contained in:
Jeroen Bakker 2023-09-26 11:19:04 +02:00
parent 729e86d5a3
commit 8f9c14145e
1 changed files with 1 additions and 20 deletions

View File

@ -10,7 +10,7 @@
int reflection_probes_find_closest(vec3 P)
{
int closest_index = -1;
int closest_index = 0;
float closest_distance = FLT_MAX;
/* ReflectionProbeData doesn't contain any gab, exit at first item that is invalid. */
@ -80,23 +80,4 @@ vec4 reflection_probe_eval(ClosureReflection reflection,
}
return vec4(0.0);
}
void reflection_probes_eval(ClosureReflection reflection, vec3 P, vec3 V, inout vec3 out_specular)
{
int closest_reflection_probe = reflection_probes_find_closest(P);
vec4 light_color = vec4(0.0);
if (closest_reflection_probe != -1) {
ReflectionProbeData probe_data = reflection_probe_buf[closest_reflection_probe];
light_color = reflection_probe_eval(reflection, P, V, probe_data);
}
/* Mix world lighting. */
if (light_color.a != 1.0) {
ReflectionProbeData probe_data = reflection_probe_buf[0];
light_color.rgb = mix(
reflection_probe_eval(reflection, P, V, probe_data).rgb, light_color.rgb, light_color.a);
}
out_specular += light_color.rgb;
}
#endif