我遇到了一个我无法解决的问题。我必须在多次使用相同的效果时绘制纹理。我正在尝试实现这样的目标:
spriteBatch.Begin();
// Use the effect multiple times with a different parameter:
lightEffect.Parameters["parameter"].SetValue(value1);
lightEffect.CurrentTechnique.Passes[0].Apply();
lightEffect.Parameters["parameter"].SetValue(value2);
lightEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);
spriteBatch.End();
仅使用第二个效果。这就是为什么我决定每次使用效果多次重绘 RenderTarget 到自身,但这也失败了,因为"The render target must not be set on the device when it is used as a texture"
.
graphicsDevice.SetRenderTarget(tempRenderTarget);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
spriteBatch.Draw(texture, new Vector2(0,0), Color.White);
spriteBatch.End();
foreach (Value value in values)
{
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
lightEffect.Parameters["paramter"].SetValue(value);
lightEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(tempRenderTarget, new Vector2(0, 0), Color.White);
spriteBatch.End();
}