I have encountered a problem which I can’t solve. I have to draw a texture while using the same effect multiple times. I am trying to achieve something like this:
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();
Only the second effect is used. That is why I decided to redraw the RenderTarget to itself multiple times using the effect each time, but that also fails miserably, because "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();
}
You have to use two alternating render targets: