Opengl alpha premultiplication issue

Member
Posts: 749
Joined: 2003.01
Post: #1
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]

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
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.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #3
Thanks, I couldn't reproduce it with a normal png, I suspect the premultiplied and not got mixed somewhere while blitting Sad

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #4
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.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Premultiplication solves that problem, as Arekkusu's link explains.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #6
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.

Thanks.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 3,134 Jan 19, 2013 08:25 AM
Last Post: sealfin
  OpenGL Pixel Buffer Object setup issue dotbianry 2 3,232 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  OpenGL ES 2.0, 2D Alpha Transparency Artifacts Macmenace 3 8,013 Mar 28, 2010 11:18 PM
Last Post: AnotherJake
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 6,397 Dec 8, 2007 02:06 PM
Last Post: Malarkey
  OpenGL Issue hammonjj 2 2,940 Feb 28, 2007 12:35 PM
Last Post: ThemsAllTook