Sign in to follow this  
BMW

Direct3D Z-Buffer problem

Recommended Posts

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)

 

d3dproblem.png

 

What would be causing this?

Edited by BMW

Share this post


Link to post
Share on other sites

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 biggrin.png. 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

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