Render for video, problem with blending

You did not tell about the video resolution you use yet. Is it SD or HD? Also what is your final output? Do you need to output the final composition as video and if you do, what kind of video card do you use?

Even rendering 100 quads to a 100 textures then compositing these 100 textures might not be possible at 50 FPS. At least you cannot do it in one pass. If you need to read back the final result to system memory that makes it even less likely.

Ok, after giving my approach some more though this could work quite well (but it’s not perfect):

My first pass would have to avoid overlapping areas. This can be done with dest_alpha/inv_dest_alpha blending and solid alphas of the quads, but it wouldn’t be perfect…

Using a shader for the first pass AND blending could solve this problem. Since blending is done after fragment rendering we can output 100% alpha values for any transparencies above 0%. The alpha channel needs to be cleared after the first pass is completed.

This is how it would look like (I had no time for testing this in code, just photoshop…):

first pass using dest_alpha blending and shader:
http://img686.imageshack.us/img686/972/pass1.jpg

second pass with blending and writing alpha values.
http://img14.imageshack.us/img14/8352/pass1pre.jpg

resulting alpha:
http://img262.imageshack.us/i/alphas.jpg/

Drawing order:

  1. red
  2. green
  3. white

I hope this works in practice aswell! :o

I don’t think this works.

This way the layer closest to the camera will cover (at least in the RGB channels) everything behind it. If you set alpha to 1 when it is not zero, you effectively switch off blending.

Not if you use blending in the second pass.
The first pass is basically just there to avoid blending with the black background.
Try the image of the second pass (actually it’s the second pass blended onto the first pass) and the alpha.

This should blend correctly onto any background image?

(maybe my example does not cover all possible layer combinations…)

OK, could you try with your middle (red) layer half-transparent? Because I can’t see at what point do you mix RGB values.

The red layer is in the back, green in the middle, white is in front.
It’s not perfect. White gets blended with 100% red where red is not 100%.
The closest thing to “pemultiply” without copying the framebuffer (or portion of it) for each element, I think.

In the back? It looks if it were in the middle.