Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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?

share|improve this question
up vote 2 down vote accepted

I think you should change your for loop to something like this (you should take current pixel and few pixels around it, not only one way from current pixel):

for(int i = -2; i < 2; i++){
    for(int j = -2; j < 2; j++){
        vec2 offset = vec2(TEXEL_SIZE.x * i, TEXEL_SIZE.y * j);
        result += texture(aoSampler, TexCoord + offset).r;

Because your kernel is 4*4, it's even count, it could be still shifted. If it's odd (for example 3*3 or 5*5), it would be better.

share|improve this answer
Thanks a lot, that worked! Only you should change the <2 to <=2 – Grieverheart Jun 28 '12 at 11:39
< 2 is correct for a 4x4 kernel; <= 2 will give you a 5x5 kernel (which you should probably be using anyway). – Le Comte du Merde-fou Jun 28 '12 at 11:56
Yes, I'm using a 5x5 kernel now, cause I thought the whole point was to sample symmetrically around the current pixel. – Grieverheart Jun 28 '12 at 23:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.