How To Solve Z buffer Fighting

Started by
14 comments, last by larspensjo 11 years, 10 months ago
Hi,

Is there any other way to solve z buffer fighting without changing the near plane value.

I am using

gluPerspective(fov,(winWid/winHgt),0.001,100000.0);


Thanks,
Advertisement
Change that near plane value as well as the far plane value. Now. I'm serious.
http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm
Yes, change the near plane. 0.001 is an absolutely ridiculous value for it; unless you can demonstrate an absolute proven need to have this value for your near plane (and I highly doubt that) - change it.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

On What basis I have to Change to Near and far values. I am new to this opengl 3d Programming

Edit1:If I push the near value 1.0 or greater till 1.0 distance Its not possible to see in the viewport
Use a 24 bit depth buffer for better precision. It is supported on everything.
http://www.opengl.org/wiki/Common_Mistakes#Depth_Buffer_Precision
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

gluPerspective(fov,(winWid/winHgt),0.001,100000.0);

This is not even remotely doable with the standard depth buffer - your near plane is absolutely ridonkulous in regards to the far plane.

You have two options:
* use sane near and far distances.
* use floating point depth buffer (if your target supports them).

Use a 24 bit depth buffer for better precision. It is supported on everything.
http://www.opengl.or...uffer_Precision

Given his near far plane distances - that wont help.
You need to explain what it is you're trying to achieve.

Assuming you're using a scale of 1 unit = 1 metre, you're asking for millimetre precision over one hundred kilometres. Which is impossible given the number of bits in the depth buffer.

Try 0.1 to 1000.0, which is really pushing it, but may be acceptable in some cases.

Basically, you need to reduce the number of zeros after the decimal point for the near value, and the number of zeros after the decimal point for the far. It's the ratio between the two that counts: you're asking for a ration of 1:100000000 which can't be expressed in a 24 bit depth buffer.

EDIT - having read you're post again, what are the furthest depth values you need? Maybe try 0.001 near to 1.0 far.
If you gave us a scale for your scene we could give you better guesses as to what values you should use.
1 = centimeters?
1 = meters?

If 1 unit = 1 centimeter (Half-Life 2, GoldenEye 007, Final Fantasy VII), you could probably get away with ranges from 10.0 to 100000.0. The low value makes more of a difference than the high value, so increasing this improves your Z quality by the most amount. 100,000 is normally a ridiculous far value, but with a near of 10.0 it isn’t too bad. Still might have some Z-fighting in detailed areas at a long-medium range or somewhat-far range.

If 1 unit = 1 meter, 0.1 to 1000.0 would be the equivalent.

In any case, you generally do not need a near value smaller than the radius of your player. For example, in an FPS the player is a capsule or cylinder, both of which have some fixed radius that keeps them that distance from walls etc. Since you can’t get closer than that to anything in the scene, your near distance should be just slightly under that value. 0.95 is often reasonable if 1 unit = 1 foot.

In any case, a near value of 0.001 is never acceptable.

If you truly need large viewing distances, use logarithmic Z.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

All of the above, plus: I guess you have a low near clipping distance because you want to draw a first person shooter hand model. In that case there is a trick that everyone uses. Render the hand model in a seperate clip space after you have rendered everything else.

This topic is closed to new replies.

Advertisement