ShAdeVampirE

My problem is: I just want to draw some objects to a render target, and than save it to texture -> post process it. It works, if I turn off multisample. But if it's turned on, it behave like DepthBuffer would be turned off (the last drawed object will be the nearest, even if it's far away), but it's not. Again, if I only turn off the multisample, it works fine, if I turn it on, it's get crazy.


Re: XNA Framework Render target + multisample problem

Shawn Hargreaves - MSFT

The format of the depth buffer always has to match the format of the active rendertarget. The default depth buffer that we create for you will match the format of the default backbuffer, but if you make your own rendertarget, you might need to make your own depth buffer to match it.

If your rendertarget is multisampled but the main backbuffer is not, you'll have to make a multisampled depth buffer to go with your rendertarget.

If your rendertarget is not multisampled but the main backbuffer is, you'll have to make a non multisampled depth buffer to go with your rendertarget.





Re: XNA Framework Render target + multisample problem

ShAdeVampirE

I create the render target this way:

m_rtarget = new RenderTarget2D(
m_rtarget .GraphicsDevice,
m_rtarget .PreferredBackBufferWidth,
m_rtarget .PreferredBackBufferHeight,
1,
m_rtarget .PreferredBackBufferFormat
);

And I don't change the device's settings after it, so it sould match. But I was curious and print some values for checking. Depth buffer formats are the same (I printed both, render target's and graphics device's), but multisample not. And in the comment/explanation of m_backbuffer.MultiSampleType I see: ... multisampling that the device can apply

I printed it and it wrote (MultisampleType.)None. So is it possible, that the backbuffer could handle the FourSamples type, but the render target not And of course, if I get the backbuffer's data to texture (ResolveBackBuffer) it works, but it's very slow (the speed is about the half of the render target's resolve).





Re: XNA Framework Render target + multisample problem

Shawn Hargreaves - MSFT

Using that constructor, your rendertarget will not be multisampled. You'd have to use the other constructor overload if you wanted to make a multisampled rendertarget.

So, it sounds like your backbuffer might be multisampled while the depth buffer is not. Are you specifying multisampling when you create the main device, or perhaps your graphics driver control panel is set to always use multisampling





Re: XNA Framework Render target + multisample problem

ShAdeVampirE

I only change that thing U mentioned (the 2nd constructor of RenderTarget2D), and it works! ThX