XNA CullMode and DepthBuffer

Started by
2 comments, last by Lio 15 years, 9 months ago
Quick question. Ive set up a qube out of 8 vertices and 36 indices using DrawUserIndexedPrimitives(); I appears fine if i turn on ClockWise CullMode. But if i set it to None its as i can see the backside of some of the vertices through the qube. Ive set the indices so that they are clockwise. I clear the depth buffer with ClearOptions.DepthBuffer before each frame is drawn. Can someone englighten me? I cant remember to have had this problem either in Managed DX. Shouldnt clearing the depthbuffer sort this, even with CullMode set to None, so that vertices that are further away is hidden behind closer objects etc. Thank you for any reply. edit: Can my effect file play any part?
Advertisement
Have you enabled z-writes and z-culling? You should have the effect states set like this:

ZWriteEnable = true;ZEnable = true;


[Edited by - MJP on July 2, 2008 8:24:47 AM]

Providing it doesn't do anything really crazy, your effect shouldn't have much to do with this. Like MJP said, make sure your ZBuffer is enabled first. If that's set up correctly, another common cause for this behavior is using 0.0f for the near clipping plane of your projection matrix. If that's the case, try changing it to 1.0f (or as big a number that works for you) to fix it.

For more information, this article would be a good read.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Thanks alot guys.

I had it work by setting:
device.RenderState.DepthBufferEnable = true;

And thanks for the article Remigius, ive already stubled upon in earlier and its a very nice explenation of the Zbuffer and Z fighting.

This topic is closed to new replies.

Advertisement