【发布时间】:2013-09-05 13:01:32
【问题描述】:
如果我这样做,我会收到一个正常绘制的模型:
GraphicsDevice.Clear(Color.Black);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(model, modelMatrix, transforms);
但是,如果我尝试使用渲染目标,即使没有应用任何效果,结果也会非常模糊:
GraphicsDevice.SetRenderTarget(scene);
GraphicsDevice.Clear(Color.Black);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(model, modelMatrix, transforms);
GraphicsDevice.SetRenderTarget(null);
spriteBatch.Begin();
spriteBatch.Draw(scene, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.End();
唯一的区别是渲染目标的使用。 Here is a picture 左边是普通绘图,右边是渲染目标。渲染目标是这样定义的:
scene = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
我也试过这样定义:
scene = new RenderTarget2D(device, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, false, device.DisplayMode.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PlatformContents);
我在这里做错了什么?
【问题讨论】:
-
您是否尝试过禁用精灵的过滤?这可以通过重载 Begin 方法并将 SamplerState.PointClamp 提供给适当的参数来完成。
-
试一试。我认为这实际上可能看起来更糟 - 现在像素化严重且模糊。
-
您确定您的 RenderTarget 与 BackBuffer 的大小完全相同吗?如果两者大小相同,PointClamp 应该实际修复它。另外,您知道XNA/D3D9 half texel offset 吗?这是一个很长的镜头,但请尝试compensating for it 看看是否有变化。
-
确保您使用与 BackBuffer 相同的设置。您需要注意许多选项 - 但我不记得在使用 RenderTarget2D 时遇到过问题。尝试使用这个
new RenderTarget2D(GraphicsDevice, pixelWidth, pixelHeight, false, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8);这是我使用的。
标签: c# xna rendertarget