Opengl alpha premultiplication issue - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Opengl alpha premultiplication issue (/thread-2153.html)
Opengl alpha premultiplication issue - Najdorf - Nov 12, 2008 08:48 PM
Is it possible to disable Opengl from using alpha premultiplication?
Lucky me i found out a case where it causes problems, I think I also figured out why:
[edited: changed wrong interpretation to the right one]
Say you have 2 pixels (one next to the other) one is white (1,1,1) with 1 alpha, the other, one is black (0,0,0) with alpha=0.
What's the problem you say? The problem is that when opengl "zooms out" and linearly combines the two for color and alpha it gets a pixel that has color (0.5,0.5,0.5) and alpha 0.5, so a semi-transparent gray, not a semi-transparent white one as it should be.
[edit this is not caused by alpha premultiplication, it is actually fixed by it]
Opengl alpha premultiplication issue - arekkusu - Nov 12, 2008 09:11 PM
The input image data, the fragment (like TexCombine), and pixel (like blending) operations you apply are entirely under your control. It's up to you to set up the state to produce the result you want.
And, you're describing the general problem of linear interpolation, but I think you've got your terms backwards-- in situations where you're doing compositing-type blending, you want premultiplied data. It does the right thing for interpolation in exactly the situation you're describing.
For other situations, like bump mapping with a gloss map in the alpha channel, you don't want the input data premultiplied, and it's up to you to set up the rest of the pipeline to produce the values you want.
Opengl alpha premultiplication issue - Najdorf - Nov 12, 2008 10:58 PM
Thanks, I couldn't reproduce it with a normal png, I suspect the premultiplied and not got mixed somewhere while blitting
Opengl alpha premultiplication issue - Najdorf - Nov 13, 2008 02:05 AM
I found the problem, basically it was the problem described in your link (i.e. the color of the transparent pixels was way off from the color of the color of the visible pixel close to it, and it still got counted in when performing linear combinations).
To solve this you have to go and edit also the colors of the "invisible" pixels so that they're about the same color of the close "visible" pixels.
Despite all my efforts I didn't find a way to do this is either photoshop or gimp... desperate I ended used up trying Seashore ( http://seashore.sourceforge.net/ ) which worked as a charm for this.
Opengl alpha premultiplication issue - OneSadCookie - Nov 13, 2008 03:57 AM
Premultiplication solves that problem, as Arekkusu's link explains.
Opengl alpha premultiplication issue - Najdorf - Nov 13, 2008 09:49 AM
Yeah I understand now, I thought there was something more fishy going on (like pixels with 0 alpha not getting pre-multiplied, while the others yes) but turns out I was wrong.