From be8ef302bc1de6ca7cdc00b870463b2648f49449 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 10 Oct 2022 22:07:07 +0100 Subject: [PATCH] Make SSR water verticals behave better --- assets/voxygen/shaders/clouds-frag.glsl | 33 ++++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 599b541493..38d430b964 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -122,22 +122,25 @@ void main() { vec2 suv = (clippos.xy / clippos.w) * 0.5 * vec2(1, -1) + 0.5; float d = -depth_at(suv); if (d < svpos.z * 0.8 && d > svpos.z * 0.999) { - t -= 1.0 / float(MAIN_ITERS); - // Do a bit of extra iteration to try to refine the estimate - const int ITERS = 8; - float diff = 1.0 / float(MAIN_ITERS); - for (int i = 0; i < ITERS; i ++) { - vec3 swpos = mix(wpos, ray_end, t); - svpos = (view_mat * vec4(swpos, 1)).xyz; - vec4 clippos = proj_mat * vec4(svpos, 1); - vec2 suv = (clippos.xy / clippos.w) * 0.5 * vec2(1, -1) + 0.5; - float d = -depth_at(suv); - t += ((d > svpos.z * 0.999) ? -1.0 : 1.0) * diff; - diff *= 0.5; + // Don't cast into water! + if (texture(sampler2D(t_src_color, s_src_color), suv).a >= 1.0) { + t -= 1.0 / float(MAIN_ITERS); + // Do a bit of extra iteration to try to refine the estimate + const int ITERS = 8; + float diff = 1.0 / float(MAIN_ITERS); + for (int i = 0; i < ITERS; i ++) { + vec3 swpos = mix(wpos, ray_end, t); + svpos = (view_mat * vec4(swpos, 1)).xyz; + vec4 clippos = proj_mat * vec4(svpos, 1); + vec2 suv = (clippos.xy / clippos.w) * 0.5 * vec2(1, -1) + 0.5; + float d = -depth_at(suv); + t += ((d > svpos.z * 0.999) ? -1.0 : 1.0) * diff; + diff *= 0.5; - new_uv = suv; + new_uv = suv; + } + break; } - break; } t += 1.0 / float(MAIN_ITERS); } @@ -155,7 +158,7 @@ void main() { clamp((new_dist - dist * 0.5) / (dist * 0.5), 0.0, 1.0), max(dot(normalize(new_wpos - wpos), refl_dir) - 0.95, 0.0) / 0.05 ) - ); + ) * 0.85; if (merge > 0.0) { vec3 new_col = texture(sampler2D(t_src_color, s_src_color), new_uv).rgb;