3

What options does the Metal API offer for increasing the precision of the depth buffer, particularly for objects that are farther away?

I've found that even with the nearZ value set uncomfortably far from the camera and the farZ value set uncomfortably close there is still a significant amount of z-fighting between nearby polygons. The depth buffer precision seems to be fantastic for objects that are close to the camera, but really lousy for things that are farther away.

This article suggests some great solutions to the problem, but the code samples are all geared toward OpenGL and DirectX.

How could one go about implementing one of these solutions (i.e. a logarithmic depth buffer) using the Metal API and/or Metal shaders?

llama591
  • 453
  • 5
  • 15
  • According to Metal by Example, http://metalbyexample.com/up-and-running-3/) Metal's depth buffer is a logarithmic function of the pixel's depth from 0 to 1 between the near and far clipping planes. I couldn't independently verify it via the developer documentation. If that's right you get a logarithmic depth buffer by default. You might want to ask about specific problems also on the apple developer forums for metal. – Bjorn Oct 19 '16 at 05:22
  • Do you know what bit depth your depth buffer has. If you're using a 16-bit depth buffer then you might have poor precision. 24-bit depth is suitable for most use cases. – Columbo Oct 19 '16 at 19:50
  • 1
    @Columbo I'm using a depth buffer with 32-bit floats (MTLPixelFormatDepth32Float). – llama591 Oct 20 '16 at 01:53
  • 1
    Can you quantify how close these objects are in world space? Is it possible that they're not merely close, but actually coinciding (down to whatever floating-point precision is applicable, in which case more depth buffer precision won't really help you)? If you can share an image or video of the problem, it might help us suggest solutions. – warrenm Oct 21 '16 at 23:19

0 Answers0