Jump to content
  • Advertisement
Sign in to follow this  
DXcoder66

Z-buffer problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. ???

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!