Premultiplied Alpha (in OpenGL)

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.
  • More

Further Reading

Here’s where I first read about this technique:

Also (XNA-oriented):

About Martin

I'm a freelance programmer. Between jobs, I work on the game described on this site.
This entry was posted in Code, OpenGL. Bookmark the permalink.

Comments are closed.