Talk:Blending: Difference between revisions
Erichaines (talk | contribs) I suggest that the general alpha computation should be put on this page |
(No difference)
|
Revision as of 03:51, 24 January 2016
The text below is from http://www.realtimerendering.com/blog/gpus-prefer-premultiplication/ - once we get this page fixed, I'll remove it from my blog post.
I noticed that the OpenGL wiki's blending page I link to has an error. It says to use these settings if your source (and destination) is premultiplied:
glBlendEquationSeparate(GL_FUNC_ADD,GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ZERO); // not correct for the general case
This is not general - it assumes the destination's alpha is zero (which means the destination's fully transparent), as it simply sets the final alpha to be the same as the source alpha.
The proper settings are:
glBlendEquationSeparate(GL_FUNC_ADD,GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
This computes the final alpha as the source alpha's area plus the remaining area times the destination alpha's coverage, classic Porter & Duff. Might as well get it right since it costs nothing extra to compute. I tried to change the entry on the wiki, but it was reverted - discussion has commenced.
All the above said, I could be wrong - the OpenGL API for blending is one area that's tricky to understand, and I wouldn't at all be shocked if I'm misinterpreting here. GL_ONE,GL_ZERO to me means "multiply the source alpha by one, the destination alpha by zero", which would then mean you're saving just the source alpha, clearly incorrect if there's a destination alpha > 0.