# Large View Distances and Z-Fighting

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

## Recommended Posts

Hi,
I am using large view distances, which means that the far plane of the fov is usually very "far away".
That results in z fighting artifacts.
Is there a way to reduce this, besides moving the near plane far away?

Thanks

##### Share on other sites
Whats your depth stencil format? Maybe you forgot to clear D3DCLEAR_ZBUFFER somewhere?

##### Share on other sites

Hi,
I am using large view distances, which means that the far plane of the fov is usually very "far away".
That results in z fighting artifacts.
Is there a way to reduce this, besides moving the near plane far away?

Thanks

You could try to use a higher bit depth for your depth buffer. 32bit or even 32bit floating point.

##### Share on other sites
Besides increasing the near-plane, some other options are:
• Counter-intuitively, increase the far-plane value
• Use logarithmic depth buffer tricks
• Use a floating-point format depth target, with near and far swapped (far=0 and near=1)
• Render the scene in several passes (e.g. from 1km to 10km, followed by 0km to 1km)

##### Share on other sites
Moving the near plane only a tiny amount forward can make a massive difference to Z fighting because Z is not stored linear in a standard pipeline. Obviously the actual scale of your world has some effect as well. We normally push the near plane as far as we can before it starts causing intersecting with levels and player issues.

##### Share on other sites

Besides increasing the near-plane, some other options are:
• Counter-intuitively, increase the far-plane value
• Use logarithmic depth buffer tricks
• Use a floating-point format depth target, with near and far swapped (far=0 and near=1)
• Render the scene in several passes (e.g. from 1km to 10km, followed by 0km to 1km)

Reason for the first is that precision is much much higher closer to the near plane. Pushing the farplane further brings everything closer to the high precision area, without risking clipping close-up geometry.

Swapping far and near is great for when you dont need z precision close to the camera.

Rendering the scene in several passes looks to be what GTA4 does. You have the advantage in this case of being able to save GPU time by staggering z slices, and even rendering them into less-than-fullscreen render targets.

##### Share on other sites

[quote name='Hodgman' timestamp='1317193177' post='4866711']
Besides increasing the near-plane, some other options are:
• Counter-intuitively, increase the far-plane value
• Use logarithmic depth buffer tricks
• Use a floating-point format depth target, with near and far swapped (far=0 and near=1)
• Render the scene in several passes (e.g. from 1km to 10km, followed by 0km to 1km)

Reason for the first is that precision is much much higher closer to the near plane. Pushing the farplane further brings everything closer to the high precision area, without risking clipping close-up geometry.[/quote]

##### Share on other sites
Thank you all for your replies and suggestions

##### Share on other sites
Use an inverted z (0=far, 1=near), this can distribute the values more evenly through the values the zbuffer uses to store the depth. There should be plenty of examples on the internet on how to do this.

Make sure your model transforms are setup to be relative to the camera, and skip going into the world coordinate system. If you have some shader code which depends on needing to know the true world position of the vertices or pixels, you should add that separately as a separate feature. If you don't do this, models that are transformed away from the origin before going into viewspace can lose a large number of bits and their vertices will start snapping to a fairly coarse grid of whatever the floating point precision is relative to the veritces distance from the origin. If the mesh animates or rotates the vertices making up each triangle will snap at different times from each other, causing the triangles to wobble.

• ### 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!

• 11
• 15
• 21
• 26
• 11