Jump to content
  • Advertisement
Sign in to follow this  
Hiyar

Large View Distances and Z-Fighting

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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]
Thanks, I had just been about to ask about that :-)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!