Sign in to follow this  
whather

Z-fighting??

Recommended Posts

Hey guys, I'm getting z-fighting type problems when I'm trying to render a simple mesh. Z-fighting should only occur at extreme distances from the camera but I'm getting something similar here. I might have a bad render setting set or something. Does anybody know what is wrong? Correct version (.X file viewer): http://staff.washington.edu/ghempton/correct.JPG My version: http://staff.washington.edu/ghempton/z-fighting1.JPG Thanks!

Share this post


Link to post
Share on other sites
It all depends on your zbuffer resolution. I think this is usually 32-bits. It should normally only happen at far distances from the camera, but it is dependent on the near and far clip planes. What values do you have those set at when you create your projection matrix? One of the easiest way to reduce z-fighting is to increase the near clip plane (further from the camera), doubling the near clip plane is the same as halving the far clip plane as far as the zbuffer is concerned.
I'm assuming you are clearing the zbuffer each frame.
You might also consider turning off the zbuffer when you want to render on top. This is the best solution but rarely possible.

Share this post


Link to post
Share on other sites
Assuming you created a depth buffer (yourself or via AutoDepthStencil), and enabled it (SetRenerState(D3DRS_ZENABLE, true);), there is a common mistake in setting up your projection matrix. You near plane may be too near. A value of 0 will destroy all attempts at Z buffering. The exact value depends on the scale of your world, but as a rule of thumb, aim for far=100*near or 1000*near, or so. The near plane has much more effect than the far plane does. The larger you can make the near plane, the better.

Share this post


Link to post
Share on other sites
Thanks guys, the problem was with my near plane. I had my near plane was set at 0.01f and far plane was set at 10000.0f. I changed the near plane to 1.0f and it works perfectly. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this