Im just experimenting with pixel shader. I found a nice blur effect and now Im trying to create an effect of blurring an image over and over.
HOW I want to do that: I want to render my image hellokittyTexture in a RenderTarget applying the blur effect, then replace hellokittyTexture with the result of that render and do it over and over again every Draw iteration:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.SetRenderTarget(buffer1);
// Begin the sprite batch, using our custom effect.
spriteBatch.Begin(0, null, null, null, null, blur);
spriteBatch.Draw(hellokittyTexture , Vector2.Zero, Color.White);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
hellokittyTexture = (Texture2D) buffer1;
// Draw the texture in the screen
spriteBatch.Begin(0, null, null, null, null, null);
spriteBatch.Draw(hellokittyTexture , Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
But I get this error "The render target must not be set on the device when it is used as a texture." Because hellokittyTexture = (Texture2D) buffer1;
is not copying the texture but the reference to the RenderTarget (basicly they are the same object after the asignation)
Do you know a nice way to get the Texture inside the RenderTarget? or a more elegant way to do what Im trying?