#version 450 layout(location = 0) in vec2 inTextCoord; layout(location = 0) out float outAO; layout(set = 0, binding = 0) uniform sampler2D ssaoSampler; layout(set = 0, binding = 1) uniform sampler2D viewPosSampler; void main() { vec2 texelSize = 2.0 / vec2(textureSize(ssaoSampler, 0)); float centerAO = texture(ssaoSampler, inTextCoord).r; float centerDepth = texture(viewPosSampler, inTextCoord).z; float totalAO = centerAO; float totalWeight = 1.0; float weights[4] = float[](0.227027, 0.1216216, 0.054054, 0.016216); int offsets[4] = int[](-2, -1, 1, 2); const float Sharpness = 20.0; for (int i = 0; i < 4; i++) { vec2 offsetH = vec2(float(offsets[i]), 0.0) * texelSize; vec2 uvH = inTextCoord + offsetH; float neighborAOH = texture(ssaoSampler, uvH).r; float neighborDepthH = texture(viewPosSampler, uvH).z; float weightH = weights[i] * max(0.0, 1.0 - Sharpness * abs(centerDepth - neighborDepthH)); totalAO += neighborAOH * weightH; totalWeight += weightH; vec2 offsetV = vec2(0.0, float(offsets[i])) * texelSize; vec2 uvV = inTextCoord + offsetV; float neighborAOV = texture(ssaoSampler, uvV).r; float neighborDepthV = texture(viewPosSampler, uvV).z; float weightV = weights[i] * max(0.0, 1.0 - Sharpness * abs(centerDepth - neighborDepthV)); totalAO += neighborAOV * weightV; totalWeight += weightV; } outAO = totalAO / totalWeight; }