0

If I do just this, I receive a model drawn normally:

GraphicsDevice.Clear(Color.Black);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(model, modelMatrix, transforms);

However, if I attempt to use a render target, even with no effects applied to it, the result is incredibly blurry:

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();

The only difference at all is the use of the render target. Here is a picture with the normal drawing on the left, and the render target drawing on the right. This is how the render target is defined:

scene = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

I've also tried defining it this way:

scene = new RenderTarget2D(device, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, false, device.DisplayMode.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PlatformContents);

What did I do wrong here?

Fibericon
  • 5,684
  • 12
  • 37
  • 64
  • Have you tried disabling the filtering on your sprites? This can be done with an overload of the Begin method and supplying SamplerState.PointClamp to the appropriate argument. – dowhilefor Sep 05 '13 at 13:05
  • Just gave it a shot. I think that might actually look worse - it's heavily pixelated as well as blurred now. – Fibericon Sep 05 '13 at 13:07
  • 1
    Have you made sure that your RenderTarget is exactly the same size as the BackBuffer? If both are the same size, PointClamp should actually fix it. Also, are you aware of the [XNA/D3D9 half texel offset](http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/)? It's a long shot, but try [compensating for it](http://gamedev.stackexchange.com/questions/28836/pixel-perfect-rendering-to-a-rendertarget-with-a-fullscreen-quad) and see if something changes. – Lucius Sep 05 '13 at 13:41
  • Make sure you are using the same settings as the BackBuffer. There are a number of options you need to be aware of - but i do not recall ever having problems when i used RenderTarget2D. Try using this `new RenderTarget2D(GraphicsDevice, pixelWidth, pixelHeight, false, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8);` its what I used. – Michael Aquilina Sep 05 '13 at 17:59

1 Answers1

1

Make sure you are using the same settings as the BackBuffer.

There are a number of options you need to be aware of - but I do not recall ever having problems when I used RenderTarget2D.

Try using this (its what I used and it worked fine for me):

new RenderTarget2D(GraphicsDevice, pixelWidth, pixelHeight, false, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8); 
Michael Aquilina
  • 5,352
  • 4
  • 33
  • 38