Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to reverse z buffer

Discussion in 'Shaders' started by harpingseal, Oct 18, 2021.

  1. harpingseal

    harpingseal

    Joined:
    Sep 3, 2020
    Posts:
    57
    how to reverse z buffer,since modern gpu use reverse eg metal,and i have an asset that the shader require depth buffer,so how can i forcefully reverse it on shader.and also,if possible,use the new depth mode on old gpu,instead of just reverting it
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    1-depth if it's normalized, assuming you meant depth buffer.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    If you’re using any of the built in macros for the depth to convert it into linear 0.0 to 1.0 depth or linear eye depth, those all handle the difference between reversed and non-reversed depth for you.

    It’s relatively rare you use the raw depth by itself. Depending on how it’s being used, 1-depth may or may not be enough.