Premultiplied alpha halos - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Premultiplied alpha halos (/thread-3501.html)
Premultiplied alpha halos - IBethune - Feb 11, 2007 12:19 PM
Just started layering up some transparent quads using OpenGL. The images are PNGs exported from Photoshop, loaded with SDL_image. I'm using the (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) options to my blend function, but I get nasty white halos around the edges of my image. Googling around a bit suggests that this is due to premultiplied alpha channels, but I have struggled to find a coherent explanation, and more important, a solution to this problem.
Anyone here know about this, and have any suggestions?
Premultiplied alpha halos - ThemsAllTook - Feb 11, 2007 12:44 PM
It's actually the other way around. Premultiplied alpha helps solve the halo problem.
Premultiplied alpha works like this: Instead of using R, G, B, A as normal, you use R*A, G*A, B*A, A. So, any non-opaque pixels's color values are pulled toward zero. You can do this either as preprocessing on the image file itself, or at runtime when you load it. So, if you premultiply alpha and switch your blendFunc to (GL_ONE, GL_ONE_MINUS_SRC_ALPHA), you should theoretically stop seeing halos.
I think the exact specifics of why this works are floating around and old thread on this forum somewhere, but the above is at least what you need to know to implement it.
Premultiplied alpha halos - Jake - Feb 11, 2007 01:22 PM
I know I was involved in a thread here that had a solution. I would find it for you but there is a 60 second wait in between searches and I didn't find it on my first two attempts and I'm not going to keep waiting 60 seconds... (this needs changed)
Premultiplied alpha halos - IBethune - Feb 11, 2007 01:31 PM
Thanks for the help guys - I just wrote a pre-multiplication step into my image loading code, and changed the blend function to GL_ONE, GL_ONE_MINUS_SRC_ALPHA, and bingo, nasty halos are gone.
Premultiplied alpha halos - Skorche - Feb 11, 2007 01:56 PM
It works because of the way linear filtering works. Say you have black image on a white background with the alpha masking out the background. If the pixels aren't perfectly aligned, you'll get some grey-ish pixels with a medium transparency.
Premultiplied alpha halos - OneSadCookie - Feb 11, 2007 01:56 PM
A thread with an explanation is here: http://www.idevgames.com/forum/showthread.php?t=7560 but I don't think that's the original...
I just use google with site:idevgames.com to search the forums. No 60-second restriction, and it gives better results, too.