Results 1 to 2 of 2

Thread: Logarithmic depth in Vulkan?

  1. #1
    Join Date
    Jun 2018

    Logarithmic depth in Vulkan?


    My existing renderer targets OpenGL 3.3 with strictly no extensions. I'm planning to write a new version of the renderer but targeting Vulkan instead.

    In the existing renderer, I use logarithmic depth everywhere. More specifically, each shader writes an encoded form of the negated eye-space Z value
    to `gl_FragDepth` and then I reconstruct the positions of fragments by using these encoded depth values. I don't use a separate Z buffer; the logarithmic
    depth values go straight into the depth buffer [0] [1].

    The two issues with this:

    1. Every shader has to explicitly write to `gl_FragDepth`; you can't just depend on the depth values calculated automatically by the vertex shader.
    2. It disables early Z optimizations, leading to overdraw.

    In the original article by Brano Kemen [2], he describes several workarounds
    for this (such as glDepthRangeNV). Unfortunately, all of them require the use of extensions that may not be supported everywhere. He describes most of the
    issues as being essentially OpenGL restrictions (the majority of which are not present in the DirectX implementations on the same hardware).

    So... My question is: What are my options for doing logarithmic depth buffers efficiently on Vulkan without extensions?

    I'm fine with having to explicitly write `gl_FragDepth` everywhere, but I'd really rather that this didn't entail a performance cost. Is there a conservative
    depth equivalent on Vulkan that actually improves performance?

    Code :
    Sorry... New user; forum won't let me post URLs.

  2. #2
    Junior Member
    Join Date
    Jun 2018
    I'm not sure if I understood you right. You can avoid writing to gl_FragDepth if GPU supports extension with access to glDepthRangeNV
    because in OpenGL default depth range is in (-1,1) and you need that extension to change it but you would like to avoid
    using it because not every GPU supports it.

    In Vulkan depth range is (0, 1) by default
    so you don't need to use gl_FragDepth in your shader.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean