Using a RenderTarget2D causes blurring

336 views Asked by At

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?

1

There are 1 answers

0
Michael Aquilina On BEST ANSWER

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