【发布时间】:2018-09-17 17:04:43
【问题描述】:
上面是我的问题的一个例子。我有两个完全相同的 alpha 蒙版,只是一个带有透明背景的圆形白色渐变。
我正在绘制到在屏幕上方渲染的 RenderTexture2D 以创建照明。它清除了半透明的黑色,然后在正确的位置绘制了 alpha 蒙版以看起来像灯光..
单独它工作正常,但如果两个发生冲突,例如下面的“火炬”与蓝色发光的蘑菇,您可以看到边界框透明度覆盖了已经绘制的橙色光晕。
这是我的方法:
这是创建渲染目标:
RenderTarget2D = new RenderTarget2D(Global.GraphicsDevice, Global.Resolution.X+4, Global.Resolution.Y+4);
SpriteBatch = new SpriteBatch(Global.GraphicsDevice);
这是绘制到渲染目标:
private void UpdateRenderTarget()
{
Global.GraphicsDevice.SetRenderTarget(RenderTarget2D);
Global.GraphicsDevice.Clear(ClearColor);
// Draw textures
float i = 0;
foreach (DrawableTexture item in DrawableTextures)
{
i += 0.1f;
item.Update?.Invoke(item);
SpriteBatch.Begin(SpriteSortMode.Immediate, item.Blend,
SamplerState.PointClamp, DepthStencilState.Default,
RasterizerState.CullNone);
SpriteBatch.Draw(
item.Texture,
(item.Position - Position) + (item.Texture.Size() / 2 * (1 - item.Scale)),
null,
item.Color,
0,
Vector2.Zero,
item.Scale,
SpriteEffects.None,
i
);
SpriteBatch.End();
}
Global.GraphicsDevice.SetRenderTarget(null);
}
我听说过深度模板等。我觉得我已经尝试了很多东西的组合,但我仍然遇到问题。在我的游戏中构建所有其他图形时,我没有遇到任何问题。
任何帮助都非常感谢谢谢! :)
【问题讨论】:
标签: xna monogame spritebatch