如何将 ZWrite 传递添加到透明着色器图形?

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

我一直在努力实现 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 我想出了以下使用我制作的着色器图的着色器。

使用此着色器可以完全正常地显示着色器图:

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"

    }

}

所以我尝试添加一个 ZWrite 通道,但是这个着色器什么也不会显示(但场景视图中的轮廓仍然像它在那里一样工作):

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"

    }

}

除了我在这里写的以外,我对 ShaderLab 的经验或知识很少,所以我可以做些什么来使 UsePass 与我需要添加的 ZWrite 通道一起工作?

事实证明,LWRP/URP 仅使用第一遍是一个“特征”。 https://issuetracker.unity3d.com/issues/lwrp-only-first-pass-gets-rendered-when-using-multi-pass-shaders

我可能会通过使用两个相互分层的渲染网格来解决这个问题。一个将执行 ZWrite(第一个),另一个将只是普通着色器图。

更新 这有效: