• 15
• 15
• 11
• 9
• 10

# Drawing only the the z-buffer

This topic is 3082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What I am trying to do is for certain objects draw only to the z-buffer. This way that object can occlude others without actually being visible. What i used to do is this:
    if(m_bRenderToZBufOnly)
pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,0x00000000);

RenderObj(pd3dDevice);

if(m_bRenderToZBufOnly)
pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,0x0000000f);

This used to seem to work, but now it doesn't (yes my hardware supports COLORWRITEENABLE). Is there any other state that could be set that would effect how this works. I do notice that some objects do seem to be occluded by the z-buf only objects, but most arent. Is there some sort of drawing order problem with this technique? Is there some sort of early z-buffer rejection optimization that would effect this?

##### Share on other sites
You need to draw those occluding objects first, before drawing what is behind them. If objects behind them are drawn first, then they will not be covered later since color writes are disabled, and their image in the color buffer will still be present even though the z-buffer is overwritten by a closer object.

##### Share on other sites
Is there any way to do what i need without sorting the draws?