【发布时间】:2013-07-10 08:19:55
【问题描述】:
我只是在尝试像素着色器。我发现了一个很好的模糊效果,现在我尝试创建一个反复模糊图像的效果。
我想怎么做:我想在 RenderTarget 中渲染我的图像 hellokittyTexture 应用模糊效果,然后用渲染结果替换 hellokittyTexture 并执行每次 Draw 迭代都会一遍又一遍:
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);
}
但是我得到这个错误“渲染目标在用作纹理时不能在设备上设置。”因为hellokittyTexture = (Texture2D) buffer1;不是在复制纹理而是对RenderTarget的引用(分配后基本上是同一个对象)
您知道在 RenderTarget 中获取纹理的好方法吗?或更优雅的方式来做我正在尝试的事情?
【问题讨论】:
-
renderTarget 必须有一些允许设置其纹理数据的字段或属性或方法,要么使用它,要么只是将纹理绘制到它
标签: c# xna rendering pixel-shader