# Drawing near objects problem

This topic is 2811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

When I draw object that supose to be realy close to each other I have results like those:
[attachment=7027:fail01.JPG]
[attachment=7030:fail02.JPG]

In this case the water is about 0.1f above the ground in the "problem" area. If I zoom in a lot the problem goes off. And if I zoom out the problem gets at much more areas:

[attachment=7029:fail03.JPG]

Do you know where the problem comes from? I think is somthing about the depth testing, but still can't fix it..

Thank you in advance!

##### Share on other sites
Yes its about depth testing.

You could:
-Move the water farther from the ground
-Cut a hold in the ground where the water is
-Draw terrain, then draw water with depth testing disabled, then everything else
-Adjust the far plane closer to the near plane

##### Share on other sites
More specifically, it's related to not having enough precision to your depth buffer.

There are a number of ways to increase effective depth buffer precision:

• Make sure you are requesting the highest bit-depth buffer available (probably 32-bits).
• Try placing the near/far planes closer together (possibly varying these by the distance to the terrain).
• Try a floating-point depth buffer, or even a logarithmic one.

##### Share on other sites
Thank you very much for the answers. I have places near and far dist closer and i have separated the surfaces of the water and the ground, so the water plane and the ground plane are crossing, not overlapping as before. This fix the problem from the viewpoint of the player but if I'm looking with my global camera the problem is still there. @swiftcoder how can I check the bits of depth buffer I'm requesting? Everything I'm doing about my depth buffer is:
 glEnable (GL_DEPTH); glEnable (GL_DEPTH_TEST); 

##### Share on other sites

-Adjust the far plane closer to the near plane

With a standard perspective projection matrix, the effective way to gain more precision over the depth range is to push the near plane as far from zero as possible, instead of bringing the far plane closer to the near plane. Cutting down the draw distance does little to improve precision for the remaining view distance.

If you are using very small near plane distances, like 0.01f, 0.1f, try pushing the near plane to 1.0f, 5.0f or even 10.0f, depending on your scale, and how close to objects your camera ever goes to.

Another solution is to linearize your depth buffer. This is a very good read.

##### Share on other sites
By the way, the term for this is “Z-Fighting”.

L. Spiro

##### Share on other sites

@swiftcoder how can I check the bits of depth buffer I'm requesting?

What toolkit are you using to create your window/OpenGL context? Depth buffer precision has to be specified as you create the context.

##### Share on other sites

[quote name='Marrshal' timestamp='1328391606' post='4909655']
@swiftcoder how can I check the bits of depth buffer I'm requesting?

What toolkit are you using to create your window/OpenGL context? Depth buffer precision has to be specified as you create the context.
[/quote]
This helps, I was using 16 bit depth buffer.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75