[Bf-blender-cvs] [b9451c48419] ui-asset-view-template: EEVEE: SSR: Check reflection ray against geometric normal
Clément Foucault
noreply at git.blender.org
Wed Mar 3 21:45:20 CET 2021
Commit: b9451c4841966a6c492c1f18b3a8a030212bf6e6
Author: Clément Foucault
Date: Wed Mar 3 13:20:23 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rBb9451c4841966a6c492c1f18b3a8a030212bf6e6
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.
===================================================================
M source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
===================================================================
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;
}
More information about the Bf-blender-cvs
mailing list