How can I add an extra pass to a 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 (try to) use a shader graph I made.

Using this shader displays the shader graph normally:

Shader "Custom/BlockPreview_WriteZ"
{
    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 "Custom/BlockPreview_WriteZ"
{
    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
        }

        UsePass "Shader Graphs/BlockPreview_Graph/Pass"

    }

}

I don’t really know much about ShaderLab so I haven’t been able to make this work. Any help would be much appreciated.

You can’t. The SRPs don’t support multi-pass shaders.*

  • Technically you can kind of hack it if one pass has no LightMode tag and the other one is using a forward lit tag (like “LightMode”=“LightweightForward” or “UniversalForward”), and the HDRP has a couple of special modes specific for transparent objects including one for a depth pre-pass (“LightMode” = “TransparentDepthPrepass”). But if you’re trying to do an unlit shader with a depth pre-pass, I don’t think that’s currently possible at all.
2 Likes

Well, that’s good to find out after many hours of trying to figure out what I did wrong (/s).

Thank you. I’m going to try adding a material that renders before the shader graph that’s just the second shader without the UsePass.

This works!
5298831--532158--upload_2019-12-19_8-35-15.png

3 Likes

I’m trying this second material approach, so that I can do a depth prepass for my shader graph that has vertex animation. I would expect this would be the way to go, but it doesn’t work: UsePass "Shader Graphs/CustomPBR/DepthOnly"
As a sanity check, this UsePass does work if I use the main pass (“Universal Forward”), but I can’t figure out why DepthOnly doesn’t work. I did set the render queue of my main transparent shader graph to transparent+1 and the depth only material to transparent (also tried Geometry)

I am attempting to use the DepthOnly pass from my opaque variant of the transparent shader, in case depthonly does nothing for transparent shaders.

Found a better solution for my use case, just put all the meshes that use transparency that need a depth write on a special layer, and add a Render Objects feature with the settings below to your ForwardRenderer asset

6156738--672957--upload_2020-7-31_18-0-12.png

3 Likes

Hi,

Is there still no way to add mutliple passes in a single shader graph shader ?

Thanks

1 Like

Any update on this issue…?

1 Like

It’s an intentional limitation. One that is unlikely to be fixed.

1 Like

Unity given a smaple to fix self see-through effect in URP.
Just like #6
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.1/manual/containers/how-to-custom-effect-render-objects.html