MonoGame-BlendState-2D SpriteBatch [英] MonoGame - BlendState - 2D SpriteBatch

查看:97
本文介绍了MonoGame-BlendState-2D SpriteBatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要SpriteBatch来呈现在WPF或普通UIKit应用中所期望的图像:

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

    如您所料,
  • 部分透明的PNG会相互渲染
  • 我有一个可以修改的Alpha,最好是使用Color.White并修改A值的东西.
  • 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.

最近的一直在使用BlendState.NonPremultiplied,但是我得到了奇怪的线条,其中部分透明的PNG彼此重叠.

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

我在Windows (请参阅此处)上遇到了类似的问题,但是通过更改进行了修复XNA内容项目中的Premultiplied设置.我该如何为MonoGame做类似的事情? (我希望这里的OpenGL有区别)

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)

推荐答案

我们通过使用两种不同的设置解决了该问题.

We solved it by using two different setups.

在Windows和XNA上:

On Windows and XNA:

  • 使用BlendState.NonPremultiplied
  • 在所有PNG的内容项目上将默认设置更改为Premultiply = False
  • 要修改精灵的Alpha值,请使用Color.White并设置A
  • 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

在MonoGame和iOS上:

On MonoGame and iOS:

  • 使用BlendState.AlphaBlend
  • 按原样保留PNG
  • 要修改精灵的Alpha值,请使用Color.White * (float)Alpha / (float)byte.MaxValue
  • Use BlendState.AlphaBlend
  • Leave PNGs as-is
  • To modify Alpha value of a sprite, use Color.White * (float)Alpha / (float)byte.MaxValue

我的PNG没有预先乘以 ,它们的使用方式与您从Photoshop中获得的期望值完全相同.

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

这篇关于MonoGame-BlendState-2D SpriteBatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆