Advertisement

Trouble achieving pixel-perfect alignment when rendering off-screen buffer to back buffer

Started by August 30, 2019 02:56 PM
2 comments, last by jacksaccountongamedev 5 years, 3 months ago

Hello ?

I’m trying to achieve a 2D shadow effect in OpenGL by rendering my shadows polygons to a texture and then rendering that texture as a full-screen quad to the back buffer. The texture is the same dimensions as the screen, the quad is rendered with the coordinates of (-1.0f,-1.0f), (1.0f,-1.0f),(1.0f,1.0f), and (-1.0f,1.0f) and with the texture coordinates (0.0f,0.0f),(1.0f,0.0f),(1.0f,1.0f), and (0.0f,1.0f).

However, I can’t seem to get the texture’s pixels to line up property with the back buffer. This results in a wobbling/dancing effect as the view scrolls around. Compare the following two videos:

In this video, I render the shadow polygons to the offscreen buffer/texture and then reset the transformation matrix and render the texture to the back buffer as a full-screen quad, as described above. Notice the wobble? It’s most evident on the horizontal and vertical shadows on the top right. (Please excuse the general framerate stutter as my screen-recording software tries to keep up.)

In the next video, I render the shadow polygons directly the back buffer rather than to the offscreen texture first:

No wobble.

I’ve tried manipulating the texture coordinates in various ways, such as by moving them “inwards” by 0.5f/texturewidth and 0.5f/textureheight, but the wobble remains. Also, switching from GL_LINEAR to GL_NEAREST does not solve the issue.

Any thoughts? Thanks!

But you somehow combine two buffers right? This may be the case with interpolation between two frames, also check if you are not adding sny unwanted offset during shadow render2 tex, however it looks like they aint synchronized, may be the depth buffer issue etc. Who knows....

Advertisement

Thanks for the help. I got to the bottom of the problem :)

The issue was not with the texture coordinates but with multisampling or lack thereof when rendering off-screen.

I hadn't set up my framebuffer configuration to allow for multisampling when rendering to the texture, so the edges of the shadow polygons, which were appearing soft and smooth when rendering directly to the backbuffer, were appearing jagged and snapping to the closest pixel when rendering to the off-screen buffer. This resulted in the aforementioned jitter as the view scrolls around.

This topic is closed to new replies.

Advertisement