In a recent post I referred to premultiplied alpha and linked to a moderately wordy article on the subject. I really wanted to link to a short summary, in terms of OpenGL. This is an attempt to write such a summary.
What is Premultiplied Alpha?
- Before rendering, all RGB colour components, whether in textures, vertices or the “current colour” have been multiplied by that colour’s corresponding alpha value. (It should probably be called “premultiplied colour”, actually.)
- Blending is done with glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
(This gives us Result.rgb = Dest.rgb*(1-Source.alpha) + Source.rgb.)
- One way to think of this blend operation is that the colour’s alpha value determines the amount of background to obscure, and the colour’s RGB values are how much colour to add.
What are the Advantages?
- No state changes are needed to switch between conventional and additive blending — Just use a different colour (with zero alpha and non-zero colour channels for additive).
- You can have additive and interpolated parts in the same texture: For example, an explosion texture with additive flames and obscuring smoke.
- Textures are correctly interpolated, eliminating fringes on down-sampled cut-outs.