Talk:Blending: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
No edit summary
Making a section.
Line 1: Line 1:
# Blending of Alpha
== Blending of Alpha ==


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

Revision as of 16:49, 26 January 2016

Blending of Alpha

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.

The question is this: what does the destination alpha actually mean? The meaning of a value is defined by how it gets used. And in most cases, the destination alpha in blending operations is *never used*. You can say that it means opaque or transparent, but if you're never using the framebuffer image's destination alpha (whether in a later blend operation or a fragment shader processing step or whatever), then it doesn't mean a thing. Most of the time, its value is meaningless and therefore it may as well be the source alpha of the last pixel rendered.
Now, there may be specific cases (multi-compositing) where the destination alpha has a purpose. But in those cases, there is a second rendering operation that reads from the image that was written to. Which means the alpha has an explicit purpose, determined by the person viewing it. But without that context, no alpha can be said to be "incorrect" relative than another. That's why I added a section explaining about the blending of the alpha for the non-premultiplied case. Alfonse (talk) 11:48, 26 January 2016 (EST)