Skip to main content
GameDev.net gamedev.net
🔒 Locked

Z-fighting??

Started by whather Apr 17, 2006 at 9:32 PM 2 replies 500+ views
Original Post
whather
whather
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!
blaze02
blaze02
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.
Namethatnobodyelsetook
Namethatnobodyelsetook
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.
whather
whather
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. :)

Topic Locked

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

Sign in to reply to this topic.