Jump to content
  • Advertisement
Sign in to follow this  
grepfruit1

Z buffer problem

This topic is 4401 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

Hello, this will probably be a simple problem, but I am not able to solve it for two days. I have a simple Maze application, which loads a maze and then lets you move within it. The walls are flat - two triangles, culling is off, AutoDepthStencil is enabled, zbuffer is enabled. But the z-buffer seems to work exactly the opposite way - it draws more distant walls in front of close ones. I've tried many things (play with the culling, use two sided walls, different settings for render states) and nothing worked.. Screenshot of the problem: Many thanks. Yours truly Michael

Share this post


Link to post
Share on other sites
Advertisement
Could you provide the snippets (a few lines in 'code' tags or blocks in 'source' tags) where you set up the depth/stencil related render-states. Which depth buffer format are you specifying? - D3DFMT_D16 should be guaranteed, but others (such as D3DFMT_D32) might not be supported by your hardware...

Have you tried using the debug runtimes (see the link in my signiture) to verify there are no errors/warnings?

How have you configured your projection matrix - having a huge difference between zNear and zFar can reduce depth accuracy, thus giving you errors similar to what you've shown.

hth
Jack

Share this post


Link to post
Share on other sites
Hello,
based on your advice I have set the highest warning level and debugging libraries and found an error 'Cannot compute WNear and WFar from the supplied projection matrix', which was caused by near plane set to 0.. When I use other value, it works fine. I guess it is caused by my unfamiliarity with near/far plane values affecting the z-buffer precision..
Many thanks for your help.

Yours truly
Michael

Share this post


Link to post
Share on other sites
Yes, you can't set the near plane at 0 -- it must be greater than 0. A good rule of thumb: Set the near plane distance to at least 1/1000 of the distance to the farthest visible object.

Share this post


Link to post
Share on other sites
Glad this got sorted out, the results of setting the near plane to 0 also had me puzzled a while ago. Perhaps the method to construct the projection Matrix should really throw an ArgumentException if 0 is passed in for the near plane, since this seems to be quite a common problem.

I don't know about John's rule of thumb, but I guess it shouldn't make a difference how many bits you use for your zbuffer. Going from this interesting article, I've always found it a sound advice to push the near plane as far back as you can afford.

Share this post


Link to post
Share on other sites
Quote:
Original post by jamesw
John is that rule of thumb for a 24 bit depth buffer or a 32?


24-bit, but it is only a rule of thumb -- a starting point.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!