In order to optimize I'm trying to set up a setup which ping pong between same framebuffer two color attachments to apply some postprocess effects. It seems to work (effects are applied) but concurently I'm getting a lot of strange artifacts like:

  • blinking squares
  • borders on depth discontinuities
  • color spilling on screen (window resize removes it)

Which change or disappear partly when I for example remove one step (one post process effect) from "ping ponging".

If I do this ordinary way using different framebuffers seems to remove them but I'm not 100% sure if it is not a mess in the shaders or something but they seem fine.

In each frame I'm doing ping pong like that:

First step - render to current color attach using other fb texture

fbDeferredLighting->bindFramebuffer(); //fb which has two color attachments
//get 0 attachment from fb scene prepass to apply effect and draw on fbDeferredLighting current color attach
effect1->setTextureUniforms(fbScene, 0); 

And then repeating some number of times: swap step and drawing, using same fb swapped attachment:

//after swap - now current=1, other=0 or current=0, other=1
std::swap(colorAttachment0Current, colorAttachment0Other);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texturesDiffuse[colorAttachment0Current]->getTextureID(), 0);
glClear(GL_DEPTH_BUFFER_BIT); //only clear depth
//get other color attach and use it to apply effect on current
effectX->setTextureUniforms(fbDeferredLighting , colorAttachment0Other); 

Is this correct?

EDIT: I wonder, maybe rewrite it to compute shaders, that would simplify things.


1 Answer 1


Actually, GL_COLOR_BUFFER_BIT also need to be cleared

After creation of the framebuffer, draw buffer need to be set to:


and then after each swap:


instead of only


To clear current attachment 0. I don't really understand these clearing bits extensively but this seems to fix blinking "chess board" artifact.

Borders seems to be connected with motion blur shader.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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