// Exclusive to SSR for now #version 450 #include "compiled.inc" #include "std/gbuffer.glsl" uniform sampler2D tex; uniform sampler2D gbuffer0; // Roughness uniform sampler2D gbufferD; // Depth uniform vec2 dirInv; in vec2 texCoord; out vec4 fragColor; void main() { float roughness = textureLod(gbuffer0, texCoord, 0.0).b; if (roughness >= 0.8) { fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb; return; } if (roughness < 0.01) { fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb; return; } float blurRadius = 1.0 + roughness * 4.0; vec3 center = textureLod(tex, texCoord, 0.0).rgb; float centerDepth = textureLod(gbufferD, texCoord, 0.0).r; float w0 = 1.0 / (1.0 + roughness * 2.0); float w1 = 1.0 / (1.0 + roughness); float w2 = 1.0 / (1.0 + roughness * 0.5); float totalW = w0; fragColor.rgb = center * w0; vec2 offsets[4]; offsets[0] = dirInv * blurRadius * 2.5; offsets[1] = dirInv * blurRadius * 1.5; offsets[2] = -dirInv * blurRadius * 1.5; offsets[3] = -dirInv * blurRadius * 2.5; float weights[4]; weights[0] = w2; weights[1] = w1; weights[2] = w1; weights[3] = w2; for (int i = 0; i < 4; i++) { vec2 sampleTC = texCoord + offsets[i]; float sampleDepth = textureLod(gbufferD, sampleTC, 0.0).r; float depthWeight = exp(-abs(centerDepth - sampleDepth) * 100.0); float w = weights[i] * depthWeight; fragColor.rgb += textureLod(tex, sampleTC, 0.0).rgb * w; totalW += w; } fragColor.rgb /= vec3(totalW); }