4
\$\begingroup\$

I made a motion blur using OpenGL immediate mode, basically it involves saving screen to texture, then rendering blended texture back (let's skip the details) with something like this:

glBegin(GL_QUADS);
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex2f(0, 0); // Bottom Left Of The Texture and Quad
        glTexCoord2f(1.0f, 1.0f); glVertex2f(800, 0);   // Bottom Right Of The Texture and Quad
        glTexCoord2f(1.0f, 0.0f); glVertex2f(800,  600);    // Top Right Of The Texture and Quad
        glTexCoord2f(0.0f, 0.0f); glVertex2f(0,  600);
    glEnd();

My problem is: When I use the motion blur, seemly the blended screen get 1 pixel shifted to the opposite of (0, 0), resulting in everything getting blurry, not only the moving stuff.

The stronger I apply the effect, the stronger everything else blurs (as seemly every frame of blur get 1 more pixel shifted).

How I fix that?

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

The texel co-ordinates, if you have bilinear filtering, are falling between the texels rather than being centered.

You either need to to add half a texel to the UVs, or turn off filtering.

\$\endgroup\$
5
  • \$\begingroup\$ Thank you. I actually figured that I could turn off filtering, and it fixed. \$\endgroup\$
    – speeder
    Oct 8, 2010 at 16:49
  • \$\begingroup\$ But I am still wondering, how I add half a texel... or stuff like that. \$\endgroup\$
    – speeder
    Oct 8, 2010 at 16:50
  • 2
    \$\begingroup\$ To add half a texel, you need to adjust your texture co-ordinates. Co-ordinates are normalised to be between 0 to 1, so if you have a 800x600 texture, you need to add 1/1600 and 1/1200 to the u and v values respectively. \$\endgroup\$
    – JasonD
    Oct 8, 2010 at 21:48
  • \$\begingroup\$ I don't think this answer is correct in the interpretation of the results. The code in the question ought to map texels to pixels exactly as it stands, if the modelview/projection are set correctly (identity for MV and projection of glOrtho(0,0,w,h,...). So I'd bet that's where the issue is. \$\endgroup\$
    – Bahbar
    Oct 12, 2010 at 20:54
  • \$\begingroup\$ Well yes, you're probably right that there's something else going on here. However I think my answer is correct as far as the basic problem - something is causing the texels to be sampled in the wrong place, by just enough that it looks wrong with filtering on, but works if it's turned off. \$\endgroup\$
    – JasonD
    Oct 13, 2010 at 5:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .