EEVEE-Next: Use reflection lightprobes for raytrace fallback

This commit is contained in:
Clément Foucault 2023-08-03 17:24:48 +02:00
parent 8daebd807c
commit 4d75c0484a
2 changed files with 36 additions and 30 deletions

@ -3,13 +3,13 @@
* Use screen space tracing against depth buffer to find intersection with the scene.
*/
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_bxdf_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_types_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ray_trace_screen_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
void main()
{
@ -32,8 +32,9 @@ void main()
return;
}
vec3 P = get_world_space_from_depth(uv, depth);
Ray ray;
ray.origin = get_world_space_from_depth(uv, depth);
ray.origin = P;
ray.direction = ray_data.xyz;
vec3 radiance = vec3(0.0);
@ -83,15 +84,16 @@ void main()
// if (thickness > 0.0 && length(ray_data.xyz) > thickness) {
// ray_radiance.rgb *= color;
// }
ReflectionProbeData world_probe = reflection_probe_buf[0];
radiance = reflection_probes_sample(ray.direction, 0.0, world_probe).rgb;
int closest_probe_id = reflection_probes_find_closest(P);
ReflectionProbeData probe = reflection_probe_buf[closest_probe_id];
radiance = reflection_probes_sample(ray.direction, 0.0, probe).rgb;
hit_time = length(ray_view.direction);
}
else {
/* Fallback to nearest lightprobe. */
// radiance = lightprobe_cubemap_eval(ray.origin, ray.direction, roughness, rand_probe);
ReflectionProbeData world_probe = reflection_probe_buf[0];
radiance = reflection_probes_sample(ray.direction, 0.0, world_probe).rgb;
int closest_probe_id = reflection_probes_find_closest(P);
ReflectionProbeData probe = reflection_probe_buf[closest_probe_id];
radiance = reflection_probes_sample(ray.direction, 0.0, probe).rgb;
hit_time = 10000.0;
}

@ -1,8 +1,29 @@
#pragma BLENDER_REQUIRE(gpu_shader_math_base_lib.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_codegen_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_bxdf_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_reflection_probe_lib.glsl)
int reflection_probes_find_closest(vec3 P)
{
int closest_index = -1;
float closest_distance = FLT_MAX;
/* ReflectionProbeData doesn't contain any gab, exit at first item that is invalid. */
for (int index = 1; reflection_probe_buf[index].layer != -1 && index < REFLECTION_PROBES_MAX;
index++)
{
float dist = distance(P, reflection_probe_buf[index].pos.xyz);
if (dist < closest_distance) {
closest_distance = dist;
closest_index = index;
}
}
return closest_index;
}
#ifdef EEVEE_UTILITY_TX
vec4 reflection_probe_eval(ClosureReflection reflection,
vec3 P,
vec3 V,
@ -15,11 +36,11 @@ vec4 reflection_probe_eval(ClosureReflection reflection,
/* Pow2f to distributed across lod more evenly */
float roughness = clamp(pow2f(reflection.roughness), 1e-4f, 0.9999f);
#if defined(GPU_COMPUTE_SHADER)
# if defined(GPU_COMPUTE_SHADER)
vec2 frag_coord = vec2(gl_GlobalInvocationID.xy) + 0.5;
#else
# else
vec2 frag_coord = gl_FragCoord.xy;
#endif
# endif
vec2 noise = utility_tx_fetch(utility_tx, frag_coord, UTIL_BLUE_NOISE_LAYER).gb;
vec2 rand = fract(noise + sampling_rng_2D_get(SAMPLING_RAYTRACE_U));
@ -57,24 +78,6 @@ vec4 reflection_probe_eval(ClosureReflection reflection,
return vec4(0.0);
}
int reflection_probes_find_closest(vec3 P)
{
int closest_index = -1;
float closest_distance = FLT_MAX;
/* ReflectionProbeData doesn't contain any gab, exit at first item that is invalid. */
for (int index = 1; reflection_probe_buf[index].layer != -1 && index < REFLECTION_PROBES_MAX;
index++)
{
float dist = distance(P, reflection_probe_buf[index].pos.xyz);
if (dist < closest_distance) {
closest_distance = dist;
closest_index = index;
}
}
return closest_index;
}
void reflection_probes_eval(ClosureReflection reflection, vec3 P, vec3 V, inout vec3 out_specular)
{
int closest_reflection_probe = reflection_probes_find_closest(P);
@ -93,3 +96,4 @@ void reflection_probes_eval(ClosureReflection reflection, vec3 P, vec3 V, inout
out_specular += light_color.rgb;
}
#endif