Jump to content

  • Log In with Google      Sign In   
  • Create Account


How To Solve Z buffer Fighting


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.

  • You cannot reply to this topic
15 replies to this topic

#1 Haris072   Members   -  Reputation: 112

Like
0Likes
Like

Posted 21 June 2012 - 04:33 AM

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,

Sponsor:

#2 szecs   Members   -  Reputation: 1987

Like
2Likes
Like

Posted 21 June 2012 - 04:43 AM

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

#3 mhagain   Crossbones+   -  Reputation: 6349

Like
0Likes
Like

Posted 21 June 2012 - 04:59 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Haris072   Members   -  Reputation: 112

Like
0Likes
Like

Posted 21 June 2012 - 05:02 AM

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

Edited by Haris072, 21 June 2012 - 05:06 AM.


#5 V-man   Members   -  Reputation: 797

Like
1Likes
Like

Posted 21 June 2012 - 05:28 AM

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);

#6 tanzanite7   Members   -  Reputation: 993

Like
0Likes
Like

Posted 21 June 2012 - 05:34 AM

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).

#7 tanzanite7   Members   -  Reputation: 993

Like
0Likes
Like

Posted 21 June 2012 - 05:35 AM

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.

#8 mark ds   Members   -  Reputation: 757

Like
0Likes
Like

Posted 21 June 2012 - 06:08 AM

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.

Edited by mark ds, 21 June 2012 - 06:15 AM.


#9 L. Spiro   Crossbones+   -  Reputation: 9732

Like
1Likes
Like

Posted 21 June 2012 - 06:25 AM

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

Edited by L. Spiro, 21 June 2012 - 06:28 AM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#10 Madhed   Crossbones+   -  Reputation: 2015

Like
3Likes
Like

Posted 21 June 2012 - 06:57 AM

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.

#11 metsfan   Members   -  Reputation: 640

Like
0Likes
Like

Posted 21 June 2012 - 08:25 AM

A bit off topic, but I feel that someone should tell you that glu is deprecated, as is all of the fixed function pipeline. Since you are new to 3d graphics, I figure its worth mentioning that. You should read up on the programmable pipeline. Also, this is a great book that I love which helped me transition from fixed function pipeline to programmable pipeline: http://www.amazon.com/OpenGL-4-0-Shading-Language-Cookbook/dp/1849514763/ref=sr_1_1?ie=UTF8&qid=1340288671&sr=8-1&keywords=opengl+4.0+shading+language+cookbook

#12 dpadam450   Members   -  Reputation: 807

Like
0Likes
Like

Posted 21 June 2012 - 09:34 AM

The reason for pushing the far plane has to do with depth values being written between 0 and 1, Most depth values lie in the range .95 and up and are smashed together. If things in your scene disappear when increasing the near plane, then your objects are way too small. Try scaling them up.

#13 DemonRad   Members   -  Reputation: 282

Like
0Likes
Like

Posted 22 June 2012 - 01:38 AM

yes. more than half of machines still have fixed pipeline yet. :)

Peace and love, now I understand really what it means! Guardian Angels exist! Thanks!


#14 antiHUMANDesigns   Members   -  Reputation: 58

Like
1Likes
Like

Posted 23 June 2012 - 08:25 PM

There is another solution to Z fighting: Multi-pass rendering. Draw your scene in multiple passes. Each pass gets the full 0-1 depth range, and your draw distance can be as long as you'll like. I know this is a good solution to drawing things in space, where the great distances may need to be handled differently that normal.

#15 mhagain   Crossbones+   -  Reputation: 6349

Like
0Likes
Like

Posted 24 June 2012 - 05:55 AM

yes. more than half of machines still have fixed pipeline yet. Posted Image

But are those machines realistically in your target audience? Or are you compromising your program for the sake of hardware that nobody is even going to run it on?

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#16 larspensjo   Members   -  Reputation: 1526

Like
0Likes
Like

Posted 25 June 2012 - 05:39 AM

The real problem may be that you try to draw more than one plane at the same depth, if you have problems with depth buffer fighting. The result will be undefined, random, or flickering. Or all of the above. It is not realistic to draw two things at the same place and have any expectations on the outcome.

You have to decide what surface should be "above", and adjust the coordinates accordingly. If this doesn't help, then you need to adjust resolution (as described above).

The are special mechanisms in OpenGL that adds a small delta to target this problem. It is described in the OpenGL superbible, which I do not have access to just now.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/




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.



PARTNERS