SSAO halo artifact induced by blurring

Hi all:

I’ve finished an SSAO pass to add soft shadow to my scene, but problem arises when I try to blur the visibility texture to reduce noise. I’ve followed John Chapman’s tutorial on SSAO and this is what I get for SSAO, pre-blur:

[ATTACH=CONFIG]1552[/ATTACH]

After that, All I do is a basic standard 4x4 blur, nothing fancy. However, the standard blur can produce halos around certain edges. This is what it looks like in the same scene, but post-blur:

[ATTACH=CONFIG]1553[/ATTACH]

This is what it looks like when the SSAO pass is done at full res, not up-sampled or anything like that. The shader code for my blur pass looks like this:


uniform vec2 SSAONoiseTexSize; //4x4 noise texture size, always remains as vec2(4, 4)
uniform sampler2D SSAOOcclusionTex; //visibility texture

in {
   vec2 TexCoord; //texture coordinate, [0, 1]
} Fragment;

void main()
        int BlurIteration = int(SSAONoiseTexSize.x) / 2;
        vec2 TexelSize = 1.0f / vec2(textureSize(SSAOOcclusionTex, 0));
        float Offset = 0.5f;
        
        float SumCount = 0;
        float OcclusionSum = 0.0f;
        for (int I = -BlurIteration; I < BlurIteration; ++I)
        {
            vec2 NeighborOffset;
            if (Has(Flags, SHADER_OCCLUSION_HORIZONTAL_BLUR))
                NeighborOffset = vec2(float(I) + Offset, 0);
            else if (Has(Flags, SHADER_OCCLUSION_VERTICAL_BLUR))
                NeighborOffset = vec2(0, float(I) + Offset);
            
            float NeighborOcclusion = texture(SSAOOcclusionTex, Fragment.TexCoord + NeighborOffset * TexelSize).r;
            OcclusionSum += NeighborOcclusion;
            SumCount += 1.0f;
        }
        
        if (SumCount > 0)
            OcclusionSum /= SumCount;
        else
            OcclusionSum = 1.0f;
        
        Output0.r = OcclusionSum;
}

Output0.r is supposed to be the visibility. 1.0f is fully visible, 0.0f is completely occluded.

I’ve been thinking about why it caused that, but I can’t wrap my head around why a 4x4 blur would do that :doh:. I’d appreciate any help, thanks in advance!

Can you show the original image without SSAO, and also the SSAO depth-map generated ?
Also try a more simple blur shader, I mean without your condition.
You often have to play with the SSAO options (kernel, radius) in order to have a decent result.

Hi Silence, thanks for your reply. Sorry that I forgot to put a closure to this thread, but I found out that doing a simple blur just tends to blur the edges as well. And when that
blurred edge is magnified, it’s easy to see that the content across the edge bleed into each other, therefore produces a halo artifact when the dark/bright color matches up on the edge.
And you are indeed right that I need to play around with the SSAO options. I managed to set them so the halo artifact looks minimum. I was able to reduce the halo artifact
to an unnoticeable amount by trying to preserve the edge after the blur, so I ended up doing a bilateral blur (sort of). What I did was when sampling the neighbor texels, if the
depth of that texel is too far from the depth of the center texel, that pixel is discarded from blurring, therefore preserving the hardness of edges (sort of). It didn’t work very well
because due to discarding too many texels, the noise pattern is more pronounced. So instead of discarding the texel completely, I give them a lesser weight.