Blur gets displaced compared to original image

Posted by user1294203 on Game Development See other posts from Game Development or by user1294203
Published on 2012-06-28T09:32:56Z Indexed on 2012/06/28 15:26 UTC
Read the original article Hit count: 353

Filed under:
|
|
|

I have implemented a SSAO and I'm using a blur step to smooth it out. The problem is that the blurred texture is slightly displaced compared to the original. I'm blurring using a 4x4 kernel since that was my noise kernel in SSAO. The following is the blurring shader:


float result = 0.0;
for(int i = 0; i < 4; i++){
    for(int j = 0; j < 4; j++){
        vec2 offset = vec2(TEXEL_SIZE.x * i, TEXEL_SIZE.y * j);
        result += texture(aoSampler, TexCoord + offset).r;
    }
}

out_AO = vec4(vec3(0.0), result * 0.0625);

Where TEXEL_SIZE is one over my window resolution.

I was thinking that this is was an error based on how OpenGL counts the Texel center, so I tried displacing the texture coordinate I was using by 0.5 * TEXEL_SIZE, but there was still a slight displacement.

The texture input to my blur shader, has wrap parameters:


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

When I tell the blur shader to just output the the value of the pixel, the result is not displaced, so it must have something to do with how neighboring pixels are sampled.

Any thoughts?

© Game Development or respective owner

Related posts about opengl

Related posts about shaders