Skip to main content
gamedev.net
🔒 Locked

Z-buffer problem

Started by DXcoder66 1 reply 550+ views
Original Post
DXcoder66
DXcoder66
I am making a game engine and cannot get the z-buffer to work. My program currently loads several .x files but the surfaces of the models clearly overlap. I think I've included all the needed code, eg: d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.EnableAutoDepthStencil = TRUE; and... g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);//Turn on the zbuffer (and cleared the z-buffer on the render fuction) Pixels still show infront of those that should be in the foreground. ???
S1CA
S1CA
What are the near and far clip planes of your projection matrix set to?

1) near should not be 0 or negative.

2) near should be as high (far away from the camera) as is bearable.

3) far should be greater than near.

4) the distance between near and far should be sensible with respect to your world units and object sizes, e.g. displaying a model of a human with units in metres and a far-near distance of 1,000,000 metres is going to give you serious Z buffer resolution problems.


Choosing a 24 or 32 bit Z buffer format is also a way to reduce artifacts - but only if your clip planes are set sensibly.


Other things?

1) if you have your own viewport set, make sure the minZ and maxZ are the right way round and sensible.

2) ensure D3DRS_ZWRITEENABLE is on and D3DRS_ZFUNC is set to what you expect it to be.

3) take care when using Z bias or Depth bias render states - used incorrectly, they'll look like a broken Z buffer.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
DXcoder66
DXcoder66
Solved in 1. (I had the near plane set to 0.0).

Topic Locked

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

Sign in to reply to this topic.