diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-07-22 01:22:39 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-07-24 16:28:27 +0300 |
commit | 9906ef06b15e8aaee36858d10b419e7605cbd848 (patch) | |
tree | cf68b1dcd4f28e379511ed06ecd8fb48f5bd0ed0 /source/blender | |
parent | a3732412ad5b2adda8e820088fba76d3c8f6ea00 (diff) |
Eevee: SSR: Use noise to dither the stride banding.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl | 12 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl | 5 |
2 files changed, 10 insertions, 7 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 4473d73c5c8..411c31118c4 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl @@ -6,12 +6,11 @@ uniform sampler2DArray utilTex; #define BRDF_BIAS 0.7 -vec3 generate_ray(ivec2 pix, vec3 V, vec3 N, float a2, out float pdf) +vec3 generate_ray(vec3 V, vec3 N, float a2, vec3 rand, out float pdf) { float NH; vec3 T, B; make_orthonormal_basis(N, T, B); /* Generate tangent space */ - vec3 rand = texelFetch(utilTex, ivec3(pix % LUT_SIZE, 2), 0).rba; /* Importance sampling bias */ rand.x = mix(rand.x, 0.0, BRDF_BIAS); @@ -66,7 +65,8 @@ void main() /* Generate Ray */ float pdf; - vec3 R = generate_ray(halfres_texel, V, N, a2, pdf); + vec3 rand = texelFetch(utilTex, ivec3(halfres_texel % LUT_SIZE, 2), 0).rba; + vec3 R = generate_ray(V, N, a2, rand, pdf); /* Search for the planar reflection affecting this pixel */ /* If no planar is found, fallback to screen space */ @@ -88,7 +88,7 @@ void main() /* Note : this still fails in some cases like with normal map. * We should check against the geometric normal but we don't have it at this stage. */ if (dot(R, N) > 0.0001) { - hit_dist = raycast(depthBuffer, viewPosition, R); + hit_dist = raycast(depthBuffer, viewPosition, R, rand.x); } vec2 hit_co = project_point(ProjectionMatrix, viewPosition + R * hit_dist).xy * 0.5 + 0.5; @@ -192,8 +192,8 @@ float screen_border_mask(vec2 past_hit_co, vec3 hit) hit_co.xy = (hit_co.xy / hit_co.w) * 0.5 + 0.5; hit_co.zw = past_hit_co; - const float margin = -0.02; - const float atten = 0.02 + margin; /* Screen percentage */ + const float margin = 0.01; + const float atten = 0.075 + margin; /* Screen percentage */ hit_co = smoothstep(margin, atten, hit_co) * (1 - smoothstep(1.0 - atten, 1.0 - margin, hit_co)); vec2 atten_fac = min(hit_co.xy, hit_co.zw); diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl index 36787153afc..d2a9b5843c5 100644 --- a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl @@ -22,7 +22,7 @@ void swapIfBigger(inout float a, inout float b) } /* Return the length of the ray if there is a hit, and -1.0 if not hit occured */ -float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir) +float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir, float ray_jitter) { float near = get_view_z_from_depth(0.0); /* TODO optimize */ @@ -95,6 +95,9 @@ float raycast(sampler2D depth_texture, vec3 ray_origin, vec3 ray_dir) * the step direction for a signed comparison */ float end = P1.x * step_sign; + /* Initial offset */ + pqk += dPQK * ray_jitter; + bool hit = false; float raw_depth; for (float hitstep = 0.0; hitstep < MAX_STEP && !hit; hitstep++) { |