MonoGame - BlendState - 2D SpriteBatch

允我心安 提交于 2019-12-11 18:09:09

问题


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

  • partially transparent PNGs render on top of one another, as you would expect
  • I have an alpha I can modify, preferably something like using Color.White and modifying the A value.

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)


回答1:


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.



来源:https://stackoverflow.com/questions/10463629/monogame-blendstate-2d-spritebatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!