Skip to main content
GameDev.net gamedev.net
🔒 Locked

Depth ordering problems when using render targets

Started by Jinhua May 20, 2006 at 4:33 PM 2 replies 750+ views
Original Post
Jinhua
Jinhua
When I try to render my scene to a render target, the depth ordering will get all messed up. Polygons that are drawn last with DrawIndexedPrimitive() will show up on top, as opposed to based on the distance from the view. If I render directly to the back buffer, then everything works as expected. Another interesting bit is that both rendering with and without render targets works fine on a different machine without changing a single line of code, and I am completely baffled as to what I am missing. The machine that "works" uses an ATI card and the other machine that doesn't uses an Nvidia card. Video drivers are up-to-date for both cars, and I'm using the April 2006 DirectX SDK on both machines as well.
Jinhua
Jinhua
Ahh, so it seems that multisampling was the problem. I removed it and everything works fine now. Sorry but I'm new to render targets.

This leads to another related question that I and couldn't figure out - how do I perform antialiasing when using render targets?

Thanks!
LeGreg
LeGreg
See the documentation of IDirect3DDevice9::SetRenderTarget (the sdk doc is a good source of information, you should read it before doing any kind of work) :

Quote:
Some hardware tests the compatibility of the depth stencil buffer with the color buffer. If this is done, it is only done in a debug build.

Restrictions for using this method include the following:

The multisample type must be the same for the render target and the depth stencil surface.
The formats must be compatible for the render target and the depth stencil surface. See CheckDepthStencilMatch.
The size of the depth stencil surface must be greater than or equal to the size of the render target.


If you enable the debug runtime, it will report an error on both ATI and NVIDIA hardware.

The way to use rendertarget and multisampling is to :
- create a depth buffer with multisample_type != NONE (use CreateDepthStencilSurface)
- create an offscreen rendertarget with the EXACT same multisample_type. (use CreateRendertarget)
- call stretchrect when you're done rendering to your multisampled rendertarget to a non multisampled target.

Usually you use a separate rendertarget in order to do a render to texture.. BUT you cannot texture from an offscreen rendertarget. So that's why you have to call stretchrect from the multisampled offscreen rendertarget to the texture RT.

Note that you can also use the Backbuffer as a multisampled source instead of an offscreen rendertarget.. BUT IF you do allocate the device with the multisampled flag set. AND IF you redirect all your rendering to a rendertarget texture. THEN you'll possibly end up downsampling TWICE.

Ideally for post processing and multisampling you should have this number of surfaces created :
- a device with a regular flipchain and MULTISAMPLE_NONE. No automatic depth buffer unless you also plan to render to a non multisampled rendertarget and you need Z for that.
- an offscreen rendertarget with MULTISAMPLE != NONE
- a depth stencil buffer with MULTISAMPLE != NONE (same as above)
- a texture RT, that you will use a source for your postprocessing or whatever is your need for the rendering.

Your mileage may vary depending on what is your exact usage though..

LeGreg

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.