粒子系统:XNA Framework HiDef 配置文件不支持 Vector4 纹理上的 alpha 混合
我发现了这个关于在 XNA 中制作粒子系统的很棒的教程: http://www.catalinzima.com/tutorials/4- use-of-vtf/article-systems/
问题是它是为旧版本的 xna 和 xna 4.0 编写的。
在 DoPhysicsPass 方法中,我收到此异常:
使用渲染目标格式 Vector4 时,XNA Framework HiDef 配置文件不支持 alpha 混合或 ColorWriteChannels。
这是正在爆炸的方法
private void doPhysicsPass(string technique, RenderTarget2D resultTarget)
{
GraphicsDevice.SetRenderTarget(temporaryRT);
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
physicsEffect.CurrentTechnique = physicsEffect.Techniques[technique];
if (isPhysicsReset)
{
physicsEffect.Parameters["positionMap"].SetValue(positionRT);
physicsEffect.Parameters["velocityMap"].SetValue(velocityRT);
}
physicsEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(randomTexture, new Rectangle(0, 0, particleCount, particleCount), Color.White);
spriteBatch.End(); //<----- Exception thrown here
GraphicsDevice.SetRenderTarget(resultTarget);
spriteBatch.Begin();
physicsEffect.CurrentTechnique = physicsEffect.Techniques["CopyTexture"];
physicsEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(temporaryRT, new Rectangle(0, 0, particleCount, particleCount), Color.White);
spriteBatch.End();
}
这是 randomTexture 的初始化:
velocityRT = new RenderTarget2D(GraphicsDevice, particleCount, particleCount, false,
SurfaceFormat.Vector4, DepthFormat.None);
任何人都可以提供一些如何解决此问题的建议吗?
I found this great tutorial on making a particle system in XNA:
http://www.catalinzima.com/tutorials/4-uses-of-vtf/particle-systems/
The problem is that its written for an older version of xna and xna 4.0.
In the DoPhysicsPass method I get this exception:
XNA Framework HiDef profile does not support alpha blending or ColorWriteChannels when using rendertarget format Vector4.
Here is the method that is blowing up
private void doPhysicsPass(string technique, RenderTarget2D resultTarget)
{
GraphicsDevice.SetRenderTarget(temporaryRT);
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
physicsEffect.CurrentTechnique = physicsEffect.Techniques[technique];
if (isPhysicsReset)
{
physicsEffect.Parameters["positionMap"].SetValue(positionRT);
physicsEffect.Parameters["velocityMap"].SetValue(velocityRT);
}
physicsEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(randomTexture, new Rectangle(0, 0, particleCount, particleCount), Color.White);
spriteBatch.End(); //<----- Exception thrown here
GraphicsDevice.SetRenderTarget(resultTarget);
spriteBatch.Begin();
physicsEffect.CurrentTechnique = physicsEffect.Techniques["CopyTexture"];
physicsEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(temporaryRT, new Rectangle(0, 0, particleCount, particleCount), Color.White);
spriteBatch.End();
}
Here is the initialization of randomTexture:
velocityRT = new RenderTarget2D(GraphicsDevice, particleCount, particleCount, false,
SurfaceFormat.Vector4, DepthFormat.None);
Can anyone offer some suggestions how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您确定正确设置了
SpriteBatch
的效果吗?我不确定你是不是。看起来您已经转换了教程,该教程使用 4.0 之前的旧方式应用自定义渲染设置 (详细信息)。我怀疑您要么需要将
SpriteSortMode.Immediate
传递给Begin
(请注意,这将禁用批处理),或传递您的效果(可能设置CurrentTechnique
之后)。第二个问题简单地用异常来解释。 您需要禁用 Alpha 混合和
ColorWriteChannels
。我怀疑ColorWriteChannels
实际上已被禁用(默认)。要禁用 Alpha 混合,请尝试将BlendState.Opaque
传递给SpriteBatch.Begin
(AlphaBlend
是默认值)。我自己没有尝试将教程更新到 XNA 4.0 - 但我非常确定修复其中一个或两个问题将解决您的问题。
First of all, are you sure you're setting the effect on the
SpriteBatch
correctly? I'm not sure you are. It looks like you've converted the tutorial, which is using the old pre-4.0 way of applying custom render settings (details).I suspect you either need to be passing
SpriteSortMode.Immediate
toBegin
(note that this will disable batching), or passing in your effect (probably after settingCurrentTechnique
).The second issue is simply explained by the exception. You need to disable alpha blending and
ColorWriteChannels
. I suspect thatColorWriteChannels
is actually disabled anyway (the default). To disable alpha blending, try passingBlendState.Opaque
toSpriteBatch.Begin
(AlphaBlend
is the default).I've not tried updating the tutorial to XNA 4.0 myself - but I'm pretty sure that fixing either one or both of these things will fix your problem.