diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-03-03 15:20:23 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-03-03 16:57:25 +0300 |
commit | f746b568f30fb9abdafde5218bf212c88d953533 (patch) | |
tree | b50805a55a516cbc9ede582efae8d013de9997d3 | |
parent | 1c22b551d0c13ad90bdc6145e6fa7db763038523 (diff) |
EEVEE: SSR: Check reflection ray against geometric normal
This improve self intersection prevention. Also reduce the bias
that was making a lot of rays not being shoot at grazing angles.
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl index a4b29d68ac4..ecff28dcd38 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl @@ -80,25 +80,24 @@ void do_ssr(vec3 V, vec3 N, vec3 T, vec3 B, vec3 vP, float a2, vec4 rand) vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); vec3 R = reflect(-V, H); + const float bad_ray_threshold = 0.01; + + vec3 vNg = safe_normalize(cross(dFdx(vP), dFdy(vP))); + /* If ray is bad (i.e. going below the surface) regenerate. */ - /* This threshold is a bit higher than 0 to improve self intersection cases. */ - const float bad_ray_threshold = 0.085; - if (dot(R, N) <= bad_ray_threshold) { + if (dot(R, vNg) < bad_ray_threshold) { H = sample_ggx(rand.xzw * vec3(1.0, -1.0, -1.0), a2, N, T, B, NH); R = reflect(-V, H); } - - if (dot(R, N) <= bad_ray_threshold) { + if (dot(R, vNg) < bad_ray_threshold) { H = sample_ggx(rand.xzw * vec3(1.0, 1.0, -1.0), a2, N, T, B, NH); R = reflect(-V, H); } - - if (dot(R, N) <= bad_ray_threshold) { + if (dot(R, vNg) < bad_ray_threshold) { H = sample_ggx(rand.xzw * vec3(1.0, -1.0, 1.0), a2, N, T, B, NH); R = reflect(-V, H); } - - if (dot(R, N) <= bad_ray_threshold) { + if (dot(R, vNg) < bad_ray_threshold) { /* Not worth tracing. */ return; } |