I want to do the following:
- Render multiple semi-transparent primitives to a texture using a framebuffer object.
- Composite the texture on top of the content of the main framebuffer (screen) by binding the texture from step 1 and drawing a quad.
Before rendering to the texture in 1), I clear it with black and an alpha of zero.
The problem I encounter is the following: The color of the semi-transparent primitives are affected by the black background of the rendering texture, which I don’t want. On the other hand, I want the color of the semi-transparent primitives drawn first to be blended with the color of the primitives that come later.
Anyone knows of a simple trick to do what I want?
s.
p.s.: Currently, I’m thinking of 2 solutions:
- Use the stencil buffer to draw the semi-transparent primitives in 2 passes. First draw the part that overlaps what has been drawn before, then draw the part that overlaps the background and turn off blending.
- Write a shader that would do a similar trick.
Any other simpler way?