Blending question: clouds & pbuffers


in an earlier version of my app, I rendered billboards with cloud textures that contain alpha directly to the screen after everything else has been rendered. That worked fine. I used


But now I’m rendering all those billboards into a pbuffer with alpha and in most cases, I’m rendering the generated pbuffer texture, not the billboards. However, I don’t know how to set the right blending modes, because it always doesn’t look how it should.


  • What should be the clear color for my pbuffer?
    glClearColor(0,0,0,0)? glClearColor(1,1,1,0)?
  • What blending mode should I use to render the billboards
    into the pbuffer?
  • What blending mode should I use to render the pbuffer?

The above doesn’t work because all billboards tend to be a little bit black where it’s alpha is not 1. Also the white isn’t visible enough, because the alpha value of e.g. 0.5 is applied TWICE :frowning:

Any ideas?



It looks like you want to perform selective blending into the pbuffer. You don’t want to blend the cloud billboards with the background color, but you do want the clouds to blend with each other.

Just off the top of my head, I would suggest using the stencil buffer to facilitate the selective blend. Render the first cloud directly into the rgba pbuffer, without blending. Have the stencil buffer increment for each fragment with alpha greater than 0 (or some other small value). This will leave you with a cloud shaped stencil mask. You can use the mask to constrain blending only to regions where the cloud is, and direct writes to where the cloud is not. The remaining clouds can be added in the same way, constantly updating the stencil mask each pass.

Each cloud billboard will take two passes working this way, but I believe the results will look the way you want.