Premultiplied alpha trouble

Luminary
Posts: 5,143
Joined: 2002.04
Post: #16
Yes, you lose precision as you add transparency. It's probably really only good for masks, rather than a real alpha channel...

Bring on the 16-bit floating-point images Wink
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #17
That page you linked explains it, but to say it another way: the premultiplication solution Keith described is solving an artwork problem. That is, when you have some artwork with translucent portions (like antialiased edges) against a background color, the background matte shows up as a fringe when you composite. But that's strictly an artwork problem, not a compositing problem. If I take a rectangular photo and draw some arbitrary alpha channel on top of it, and use that as an RGBA unpremultiplied texture, it doesn't have any fringe, because there is no matte-- the original pixels from the photo are all there. if your artwork has fringes, well, it's because you drew your artwork wrong. Consider the mipmap case-- what color is your artwork going to be when it's reduced to a 1x1 pixel? Mostly the matte color? You better fix your matte.

Now, in Quartz, premultiplication is good. If I loaded that photo+alpha channel via NSImage, it'd premultiply it for me automatically (so looking at [img bitmapData], all of the transparent pixels would be black) and then [img drawAtPoint] etc are a bit faster because they can skip a multiply per pixel during repeated compositing. Note that you can't ever show the original image (turning off the alpha mask), because it's destroyed during premultiplication.

But with OpenGL, it doesn't make any difference. If you have blending on, you're taking a speed hit from reading the framebuffer destination value back. The source factor (GL_ONE or GL_SRC_ALPHA, typically) doesn't make any difference speed wise. And, if you want to, you can turn off, or fade or invert, the alpha mask, because the original image data is all still there.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #18
Valuable information, Alex! Thanks!

However, as I'm sure you've gathered by now, our artwork needs those haloes removed, and Keith's proposal works a treat. Still, I'll keep it in mind for the future. Thanks for your time, both of you!
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #19
I just put a photoshop "stroke" effect on the outside of my image (rgba) that has a color similar to the image and then put the transparency down to about 2-5%, more if I want a sort of outline. Snowball is a bit sloppy in places, but generally you won't see any halos.

I like this group of alternative solutions, though.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #20
Yeah, I guess that would've worked, if I hadn't needed to tile and overlay sprites without any visible seams. Smile
By the way, I'm looking forward to Snowball! Wink
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #21
Fenris Wrote:Too bad Ivan just translates into Iwan, which isn't very cool at all.
My grandmother and grandfather didn't speak English very well since they were Finnish so they called me Yaggo. Ain't nothin' wrong with Iwan if you ask me! Rasp
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #22
I kind of like Yaggo. Grin

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble with alpha when drawing into FBO TomorrowPlusX 19 10,932 Oct 23, 2012 02:07 PM
Last Post: TomorrowPlusX
  Premultiplied alpha halos IBethune 5 3,992 Feb 11, 2007 01:56 PM
Last Post: OneSadCookie
  png without alpha fine, png with alpha, nothing dave05 6 6,775 Jun 11, 2005 10:31 AM
Last Post: dave05
  How can I load a PNG without premultiplied alpha? Prime 6 7,335 Feb 15, 2005 08:52 PM
Last Post: arekkusu