jonathanpeppers
jonathanpeppers

Reputation: 26505

MonoGame - BlendState - 2D SpriteBatch

I need SpriteBatch to render images how I would expect in WPF or a normal UIKit app:

Closest has been using BlendState.NonPremultiplied, but I get weird lines where partially transparent PNGs overlap on one another.

I was having similar issues on Windows (see here), but fixed it by changing the Premultiplied setting in the XNA content project. How can I do similar for MonoGame? (I'm expecting there is a difference in OpenGL here)

Upvotes: 0

Views: 4102

Answers (1)

jonathanpeppers
jonathanpeppers

Reputation: 26505

We solved it by using two different setups.

On Windows and XNA:

  • Use BlendState.NonPremultiplied
  • Change the default setting to Premultiply = False on the content project for all PNGs
  • To modify Alpha value of a sprite, use Color.White and set A value

On MonoGame and iOS:

  • Use BlendState.AlphaBlend
  • Leave PNGs as-is
  • To modify Alpha value of a sprite, use Color.White * (float)Alpha / (float)byte.MaxValue

My PNGs are not pre-multiplied and are used exactly as you'd expect coming out of Photoshop.

Upvotes: 1

Related Questions