Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Z-buffer depth - is it possible to know it or set explicitely?

Discussion in 'General Graphics' started by ytrewq, Feb 28, 2021.

  1. ytrewq

    ytrewq

    Joined:
    Aug 5, 2012
    Posts:
    41
    We have some z-fighting problems in our game, which possibly can be solved by using higher precision z-buffer depth. Usual tricks with tweaking near / far clip planes of the camera will not work, because we have wide object distance range - very close and very far. So, is it possible to set z-buffer depth to 24 or 32 bits explicitely?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    10,095
    Unless you're on a mobile device, or already manually creating a render texture with a 16 bit depth, Unity uses a 32 bit depth buffer. Technically it requests a 24 bit depth buffer, but most GPUs don't actually support that anymore and provide a 32 bit depth instead.

    On Android devices that support it, there may be a setting in the Player settings to force 16 or 24 bit depth.

    On desktop and consoles, Unity also uses a reversed Z which removes a lot of additional z precision issues. However on OpenGL using a reversed Z doesn't actually help due to the clip space Z range being -1.0 to +1.0 instead of 0.0 to 1.0 like all other graphics APIs, so they don't use reversed Z there. That means mobile devices running OpenGLES can't take advantage of this, but they can if they're running Vulkan or Metal.
    https://developer.nvidia.com/content/depth-precision-visualized
     
  3. ytrewq

    ytrewq

    Joined:
    Aug 5, 2012
    Posts:
    41
    Thank you.
     
unityunity