SpriteBatch BlendState / Premultiplied Alpha Issues

Hi,

Rather confused here. I am drawing 2D sprites using this type of approach…

spriteBatch.Begin (SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, rasterizer_state);

…this works fine on iOS. However it appears that on Android all the semi-transparent areas on my images are being rendered as opaque (or something similar anyway). I’m using exactly the same source files for both projects which are ‘raw’ 24bit PNGs saved from Photoshop using ‘Save For Web’ and loaded with Content.Load().

I have tried using BlendState.NonPreMultipled instead and this gets Android working but when I draw sprites not at full opacity they seem to be fading to black somehow. Thinking about it this could be because I’m pre-multiplying the ‘tint’ colour rather than just setting an alpha value. I’d rather use the same BlendState for both platforms though and from what I’ve read BlendState.Aplha sounds as though it should be more efficient.

I’m guessing the issue has something to do with the PNGs not being saved with premultipled alpha. I don’t know why it’s working on iOS but, again, am guessing there’s some kind of pre-processing involved with PNGs on iOS.

Is there a definitive way of saving 24bit PNGs with premultiplied alpha on Mac OS? Whilst googling I found a link to an app that supposedly did it but it was Windows only.

Thanks in advance for any help…

OK, I will answer my own question in case anyone comes across the same issue. Typically almost as soon as I posted the question I came across a guide for saving as premultiplied alpha in Photoshop that works! Hard to track down though. Here it is…

===

  1. import/open a png with normal transparency
  2. duplicate the original layer
  3. create a new fill layer and fill with either white or black, depending whether you need to premultiply with black or white
  4. then merge the duplicated layer with the fill layer
  5. click the original to load the transparency as a selection
  6. select the merged layer, and create a layer mask based on that selection.

Now delete the original, and save as a png. Voila, a premultiplied anti-aliased version.

===

I used a black fill and saved as 24bit PNG with ‘Save For Web’. Now BlendState.AlphaBlend seems to be working fine on both iOS and Android. Easy to set this up as an action and use for batch processing too.

cheers