Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question LinearEyeDepth() in Shader Graph

Discussion in 'Shaders' started by ATMLVE, Sep 28, 2023.

  1. ATMLVE

    ATMLVE

    Joined:
    Jun 11, 2023
    Posts:
    52
    I'm working on a shader in shader graph that uses the depth texture. As one may know, depth texture is ordinarily the z distance off the camera's plane, where it only takes one axis into account.

    In my case however I need the actual true distance in world units. Online I've found in HLSL there is simply a function LinearEyeDepth() that does this. But I've tried many things in shader graph and so far none of them have worked. In my use case, things are grey in the center of the screen and shift to pitch black halfway to an edge. I'm working in URP.
     
  2. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    73
    if you need the distance why not just calculate the distance between the viewPos and fragment/vertex? shader graph gives you both in world space
     
    ATMLVE likes this.
  3. ATMLVE

    ATMLVE

    Joined:
    Jun 11, 2023
    Posts:
    52
    Thank you for responding! I did realize yesterday that shader graph does have the world-relative position node that does exactly what I needed, after I watched an old HLSL video that talked about not needing depth texture for this sort of thing at all which sent me looking for alternatives.
     
    POOKSHANK likes this.