From dae78e2a2cb90b612547446bf64df565f43f21fc Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Wed, 6 Sep 2023 19:44:53 +0200 Subject: [PATCH] Blur changes to avoid darkening the edges --- wadsrc/static/shaders/lightmap/frag_blur.glsl | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wadsrc/static/shaders/lightmap/frag_blur.glsl b/wadsrc/static/shaders/lightmap/frag_blur.glsl index 8dbb3069bf..b515610816 100644 --- a/wadsrc/static/shaders/lightmap/frag_blur.glsl +++ b/wadsrc/static/shaders/lightmap/frag_blur.glsl @@ -4,20 +4,29 @@ layout(set = 0, binding = 0) uniform sampler2D tex; layout(location = 0) in vec3 worldpos; layout(location = 0) out vec4 fragcolor; +vec4 centerFragColor; + +vec4 clampedSample(vec4 f) +{ + return f != vec4(0, 0, 0, 0) ? f : centerFragColor; +} + void main() { ivec2 size = textureSize(tex, 0); vec2 texCoord = gl_FragCoord.xy / vec2(size); + centerFragColor = textureOffset(tex, texCoord, ivec2(0, 0)); + #if defined(BLUR_HORIZONTAL) fragcolor = - textureOffset(tex, texCoord, ivec2( 0, 0)) * 0.5 + - textureOffset(tex, texCoord, ivec2( 1, 0)) * 0.25 + - textureOffset(tex, texCoord, ivec2(-1, 0)) * 0.25; + centerFragColor * 0.5 + + clampedSample(textureOffset(tex, texCoord, ivec2( 1, 0))) * 0.25 + + clampedSample(textureOffset(tex, texCoord, ivec2(-1, 0))) * 0.25; #else fragcolor = - textureOffset(tex, texCoord, ivec2(0, 0)) * 0.5 + - textureOffset(tex, texCoord, ivec2(0, 1)) * 0.25 + - textureOffset(tex, texCoord, ivec2(0,-1)) * 0.25; + centerFragColor * 0.5 + + clampedSample(textureOffset(tex, texCoord, ivec2(0, 1))) * 0.25 + + clampedSample(textureOffset(tex, texCoord, ivec2(0,-1))) * 0.25; #endif }