Premultiplied vs. Nonpremultiplied Alpha

[Previous] [Next]

The last aspect of alpha blending you'll need to consider is how to select whether to use premultiplied or nonpremultiplied alpha in textures. With the premultiplied alpha format, the color components stored in each pixel are already premultiplied by the alpha component. For example, a semitransparent, fully red pixel would be stored as (0.5, 0.0, 0.0, 0.5) in premultiplied format or as (1.0, 0.0, 0.0, 0.5) in nonpremultiplied format.

Premultiplied alpha is starting to gain popularity because it's more useful and more efficient than nonpremultiplied blending in some settings because of the computation time it saves during rendering.

A key point to keep in mind when you're applying a texture with premultiplied alpha is not to set up the renderer to use this formula:

resultColor = srcColor · srcAlpha + destColor · invSrcAlpha

The srcColor variable is already multiplied by srcAlpha. Instead, you should use the following formula:

resultColor = srcColor · 1 + destColor · invSrcAlpha

To linearly blend a texture stage that uses premultiplied alpha, use the D3DTOP_BLENDTEXTUREALPHAPM member with the IDirect3DDevice7::SetTextureStageState method.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net