Eevee: SSR: Don't block the ray if tracing behind object.
This requires to check for backface after a hit.
This commit is contained in:
@@ -67,11 +67,14 @@ void main()
|
||||
/* Raycast over screen */
|
||||
float hit_dist = raycast(depthBuffer, viewPosition, R);
|
||||
|
||||
/* TODO Check if has hit a backface */
|
||||
|
||||
vec2 hit_co = project_point(ProjectionMatrix, viewPosition + R * hit_dist).xy * 0.5 + 0.5;
|
||||
|
||||
/* Check if has hit a backface */
|
||||
vec3 hit_N = normal_decode(textureLod(normalBuffer, hit_co, 0.0).rg, V);
|
||||
pdf *= step(0.0, dot(-R, hit_N));
|
||||
|
||||
hitData = hit_co.xyxy;
|
||||
pdfData = vec4(pdf) * step(-0.1, hit_dist);
|
||||
pdfData = vec4(pdf) * step(0.0, hit_dist);
|
||||
}
|
||||
|
||||
#else /* STEP_RESOLVE */
|
||||
|
||||
@@ -111,7 +111,10 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir)
|
||||
raw_depth = texelFetch(depth_texture, ivec2(hitpixel), 0).r;
|
||||
view_depth = get_view_z_from_depth(raw_depth);
|
||||
|
||||
if (zmax < view_depth) {
|
||||
/* TODO user threshold */
|
||||
const float threshold = 0.5; /* In view space */
|
||||
/* Check if we are somewhere near the surface. */
|
||||
if ((zmax < view_depth) && (zmax > view_depth - threshold)) {
|
||||
/* Below surface, cannot trace further */
|
||||
hit = true;
|
||||
}
|
||||
@@ -137,20 +140,16 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir)
|
||||
raw_depth = texelFetch(depth_texture, ivec2(hitpixel), 0).r;
|
||||
view_depth = get_view_z_from_depth(raw_depth);
|
||||
|
||||
if (zmax < view_depth) {
|
||||
/* TODO user threshold */
|
||||
const float threshold = 0.5; /* In view space */
|
||||
/* Check if we are somewhere near the surface. */
|
||||
if ((zmax < view_depth) && (zmax > view_depth - threshold)) {
|
||||
/* Below surface, cannot trace further */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if we are somewhere near the surface. */
|
||||
/* TODO user threshold */
|
||||
float threshold = 0.1; /* In clip space */
|
||||
if (zmax < view_depth - threshold) {
|
||||
hit = false;
|
||||
}
|
||||
|
||||
/* Check failure cases (out of screen, hit background) */
|
||||
if (hit && (raw_depth != 1.0) && (raw_depth != 0.0)) {
|
||||
/* Return length */
|
||||
|
||||
Reference in New Issue
Block a user