unity-game-engineshaderlab

How can I add a ZWrite pass to a transparent shader graph?


I have been trying to achieve this effect from Tim-C (which all seems to be outdated, even the fixes posted in the comments) with ShaderGraph (Unity 2019.3.0f3), but as far as I know you can't do that within ShaderGraph, so after looking at this page on the ShaderLab documentation I came up with the following shaders that use a shader graph I made.

Using this shader displays the shader graph completely fine:

Shader "Custom/BlockPreview_ZWrite"
{
    Properties
    {
        //Has the same name as 'Reference' in shader graph.
        PreviewColor("Hologram Color", Color) = (0.90, 0.90, 0.90, 0.20)
    }

    SubShader
    {

        Tags {
            "Queue" = "Transparent"
            "RenderType" = "Transparent"
            "RenderPipeline" = "UniversalPipeline"
        }

        UsePass "Shader Graphs/BlockPreview_Graph/Pass"

    }

}

So I tried adding a ZWrite pass, but this shader will just display nothing at all (but the outline in the scene view still works like it's there):

Shader "Unlit/BlockPreviewZ"
{
    Properties
    {
        //Has the same name as 'Reference' in shader graph.
        PreviewColor("Hologram Color", Color) = (0.90, 0.90, 0.90, 0.20)
    }

    SubShader
    {

        Tags
        {
            "Queue" = "Transparent"
            "RenderType" = "Transparent"
            "RenderPipeline" = "UniversalPipeline"
        }

        Pass                                                                                           //
        {                                                                                              //
            ZWrite On                                                                                  //
            ColorMask 0   //Commenting out this line will just display a solid white object.           //
        }                                                                                              //

        UsePass "Shader Graphs/BlockPreview_Graph/Pass"

    }

}

Other than what I've wrote here, I have very little ShaderLab experience or knowledge, so what can I do to make the UsePass work with the ZWrite pass I need to add?


Solution

  • Turns out, LWRP/URP using only the first pass is a “feature”. https://issuetracker.unity3d.com/issues/lwrp-only-first-pass-gets-rendered-when-using-multi-pass-shaders

    I will probably get around this by using two rendered meshes layered over each other. One will do the ZWrite (first), and the other will just be the normal shader graph.

    Update This works: Screenshot of the 'Materials' array of the Mesh Renderer.