#version 450 #include "compiled.inc" #include "std/gbuffer.glsl" uniform sampler2D tex; uniform sampler2D gbuffer0; uniform sampler2D gbufferD; uniform vec2 dirInv; // texStep in vec2 texCoord; out vec3 fragColor; const int KERNEL_SIZE = 13; const float blurWeights[13] = float[](0.1, 0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.025, 0.02, 0.015, 0.01, 0.005); void main() { vec3 centerNor = getNor(textureLod(gbuffer0, texCoord, 0.0).rg); float centerDepth = textureLod(gbufferD, texCoord, 0.0).r; // skip sky pixels if (centerDepth == 1.0) { fragColor = vec3(0.0); return; } fragColor = textureLod(tex, texCoord, 0.0).rgb * blurWeights[0]; float totalWeight = blurWeights[0]; for (int i = 1; i < KERNEL_SIZE; i++) { vec2 offset = float(i) * dirInv; vec2 uvPos = texCoord + offset; vec3 norPos = getNor(textureLod(gbuffer0, uvPos, 0.0).rg); float depthPos = textureLod(gbufferD, uvPos, 0.0).r; float normalWeight = max(0.0, dot(norPos, centerNor)); normalWeight = pow(normalWeight, 8.0); // Softer normal falloff for better blending float depthWeight = 1.0 - smoothstep(0.0, 0.02, abs(depthPos - centerDepth)); float w = blurWeights[i] * normalWeight * depthWeight; fragColor += textureLod(tex, uvPos, 0.0).rgb * w; totalWeight += w; vec2 uvNeg = texCoord - offset; vec3 norNeg = getNor(textureLod(gbuffer0, uvNeg, 0.0).rg); float depthNeg = textureLod(gbufferD, uvNeg, 0.0).r; normalWeight = max(0.0, dot(norNeg, centerNor)); normalWeight = pow(normalWeight, 8.0); depthWeight = 1.0 - smoothstep(0.0, 0.02, abs(depthNeg - centerDepth)); w = blurWeights[i] * normalWeight * depthWeight; fragColor += textureLod(tex, uvNeg, 0.0).rgb * w; totalWeight += w; } fragColor /= totalWeight; }