Premultiplied alpha

From vegard.wiki
Revision as of 08:58, 19 December 2019 by Vegard (talk | contribs) (→‎See also)
Jump to navigation Jump to search

Problem

When blending a partially transparent image on top of a background image you can get artifacts in areas which are not fully transparent and not fully opaque. The problem stems from the use of texture filtering, which will interpolate values from nearby pixels without taking transparency into account.

Solution

Use premultiplied alpha; usually this means:

  • multiply RGB values by the alpha component when loading textures
  • use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

This allows texture filtering to combine the RGB and alpha components separately and produce accurate blending results.

See also