View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Direct3D Z-Buffer problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1BMW  Members

Posted 25 March 2013 - 11:09 PM

I am making a voxel engine in C++ with Direct3D.

I have rendered some voxels on the screen with colours for sides (no textures yet).

However it appears that the z-buffer isn't working properly. See image: (Image is of a "chunk" of blocks)

What would be causing this?

Edited by BMW, 25 March 2013 - 11:10 PM.

### #2Hodgman  Moderators

Posted 25 March 2013 - 11:15 PM

http://en.wikipedia.org/wiki/Z-fighting

You're probably using a value for the near plane that is too small. What near/far values are you using, and what's the size of your scene/objects?

### #3BMW  Members

Posted 25 March 2013 - 11:27 PM

http://en.wikipedia.org/wiki/Z-fighting

You're probably using a value for the near plane that is too small. What near/far values are you using, and what's the size of your scene/objects?

I was using 0.005 for near plane, changed to 0.1, much better . Each block is 1x1x1.

With 0.1 there is still some very slight z-fighting, should I increase? Or will that cause it to clip too early?

Also, how does the near plane affect z-fighting?

Edited by BMW, 25 March 2013 - 11:27 PM.

### #4Hodgman  Moderators

Posted 25 March 2013 - 11:37 PM

The encoding used by the z-buffer is approximately hyperbolic, with roughly 50% of it's precision going towards values between near and 2*near. This is unfortunate  but a necessary by-product of the way that 3D perspective math works out...

Because of this, you should always set the near plane to be as large as you can tolerate, without causing clipping errors.

http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

http://www.codermind.com/articles/Depth-buffer-tutorial.html

### #5BMW  Members

Posted 26 March 2013 - 02:07 AM

The encoding used by the z-buffer is approximately hyperbolic, with roughly 50% of it's precision going towards values between near and 2*near. This is unfortunate  but a necessary by-product of the way that 3D perspective math works out...

Because of this, you should always set the near plane to be as large as you can tolerate, without causing clipping errors.

http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

http://www.codermind.com/articles/Depth-buffer-tutorial.html

Thanks!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.