Reputation: 303441
The "normal" source-over blend equation is
outColor = srcAlpha * srcColor + (1 - srcAlpha) * dstColor
This equation does not consider the destination alpha, and as such produces poor results when the destination alpha is not 1.0.
For example, consider the case of a 50%-opaque yellow source color over a destination that is fully transparent, but has a red color. [Edit: e.g. the RGBA buffer has values of [255, 0, 0, 255]
in each channel.] The above equation results in 50% yellow blended with 50% red, tainting the yellow even though the background is fully transparent.
What is a blend equation that works with destination alpha, such that a source image with semi-transparent pixels blended over a fully-transparent target remains unchanged?
Upvotes: 1
Views: 825
Reputation: 3951
You should draw translucent objects from furthest to closest.
If you are going to draw N objects sorted by distance, when you render object i
you only need take into account the alpha of i
. All the alphas for objects < i
have already been taken into account when they were drawn.
(image from: https://www.sterlingpartyrentals.com/product/color-gels-for-par-light/)
The dstAlpha is almost never used.
In your example, having transparent red in the destination... how was the red drawn in the first place if its fully transparent?
You should always draw fully opaque objects first, and make sure that the whole screen gets something opaque drawn in to it. In 3D you can for example use cubemaps for making sure that this is the case.
(image from: https://learnopengl.com/Advanced-OpenGL/Cubemaps)
Upvotes: 0