How to blend triangles over a transparent background?

Hi everyone,

In my application I’m drawing transparent objects using blending, with Color = SrcAlpha * SrcCol + (1-SrcAlpha) * DstCol, same for the alpha.

Suppose I’d like to have the following behavior:
a number of possibly overlapping semi-transparent triangles are drawn on top of an empty (argb = 0,0,0,0) background and composited onto an opaque background gives the same result as directly drawing onto the opaque background.

Is there a way to achieve this result just by setting the right blend state and not changing the logic behind color assignment depending on the specific case (drawing on transparent/opaque background)?

Sounds like you want Premultipled Alpha. Search the forum archives for links to blog posts on this as well as images illustrating the result.

You want this for the application you’re discussing: compositing intermediate layers of the scene and then blending them on the background (or against each other).

1 Like