Premultiplied alpha: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(new page) |
(→Solution: gamma correction) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
* multiply RGB values by the alpha component when loading textures |
* multiply RGB values by the alpha component when loading textures |
||
* use < |
* use <code>glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)</code> |
||
This allows texture filtering to combine the RGB and alpha components separately and produce accurate blending results. |
This allows texture filtering to combine the RGB and alpha components separately and produce accurate blending results. |
||
Note that if sRGB textures are used (and they probably shouldn't be) then the process is different; see the article on [[Gamma|gamma correction]] for more information. |
|||
=== See also === |
=== See also === |
||
* http://www.adriancourreges.com/blog/2017/05/09/beware-of-transparent-pixels/ |
* http://www.adriancourreges.com/blog/2017/05/09/beware-of-transparent-pixels/ |
||
* https://limnu.com/premultiplied-alpha-primer-artists/ |
|||
[[Category:Graphics programming]] |
[[Category:Graphics programming]] |
Latest revision as of 10:31, 19 December 2019
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.
Note that if sRGB textures are used (and they probably shouldn't be) then the process is different; see the article on gamma correction for more information.