Search Unity

Question Depth Test Offset in Shader Graph or something equivalent?

Discussion in 'Shader Graph' started by Deleted User, Jul 22, 2021.

  1. Deleted User

    Deleted User

    Guest

    Preface: I'm still an amateur when it comes to shaders, but I feel like I'm learning a lot very quickly. Unfortunately, the basic principles that are easy to grasp within the Built-in Pipeline surface shader get buried in lines and lines of extra configuration in a Vert-Frag shader in URP. Because of that, I feel sort of stuck with Shader Graph as long as I want to be using URP.

    Maybe this is just a feature request because hours and hours of googling have brought me no closer to the solution.
    When you're configuring your depth buffer at the start of a Pass, there are three fields you can set:
    Code (CSharp):
    1. ZTest LEqual
    2. ZWrite Off
    3. Offset 0,0
    It took them a while, but they exposed ZTest and ZWrite in the Graph Inspector. I cannot figure out a way to configure Offset in Shader Graph. I have a material that must get drawn on top of another, and Offset is the only way I've been able to get it consistently rendering on top (Messing with ZTest and ZWrite did not fix it, there was still significant z-fighting).

    At this point all I can do is scroll through the generated shader code and paste "Offset -1, -1". I'm not looking forward to having to do that every time I modify the shader. Is there any other way to accomplish the same thing as Offset -1, -1, or a way to directly configure it within Shader Graph?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    There's no way to use Offset with Shader Graph without manually modifying the shader code like you are. The closest thing you can do is manually offsetting the vertex position like this:

    https://forum.unity.com/threads/sha...-property-in-shader-code.663550/#post-4459513

    This is a hack though, and does not accurately reproduce the full functionality of Offset. Though part of the problem is the implementation of Offset isn't set and changes depending on how the graphics card decided to implement it. This gets part of the second value, though the offset distance is in object space rather than depth precision space.
     
  3. Deleted User

    Deleted User

    Guest

    Thanks! This totally worked for my use case. Even the tiniest OffsetFactor (0.001) fixed all of the Z-fighting. I'm honored to be responded to by the great @bgolus after reading so many of your solutions to others' problems in my journey to figure out URP.
     
    marios-trophygames likes this.