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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

How can I add an extra pass to a Shader Graph?

Discussion in 'Shaders' started by SonicBlue22, Dec 19, 2019.

  1. SonicBlue22

    SonicBlue22

    Joined:
    Sep 10, 2018
    Posts:
    3
    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:

    Code (Boo):
    1. Shader "Custom/BlockPreview_WriteZ"
    2. {
    3.     Properties
    4.     {
    5.         //Has the same name as 'Reference' in shader graph.
    6.         PreviewColor("Hologram Color", Color) = (0.90, 0.90, 0.90, 0.20)
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.  
    12.         Tags {
    13.             "Queue" = "Transparent"
    14.             "RenderType" = "Transparent"
    15.             "RenderPipeline" = "UniversalPipeline"
    16.         }
    17.  
    18.         UsePass "Shader Graphs/BlockPreview_Graph/Pass"
    19.  
    20.     }
    21.  
    22. }
    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):

    Code (Boo):
    1. Shader "Custom/BlockPreview_WriteZ"
    2. {
    3.     Properties
    4.     {
    5.         //Has the same name as 'Reference' in shader graph.
    6.         PreviewColor("Hologram Color", Color) = (0.90, 0.90, 0.90, 0.20)
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.  
    12.         Tags {
    13.             "Queue" = "Transparent"
    14.             "RenderType" = "Transparent"
    15.             "RenderPipeline" = "UniversalPipeline"
    16.         }
    17.  
    18.         Pass
    19.         {
    20.             ZWrite On
    21.             ColorMask 0
    22.         }
    23.  
    24.         UsePass "Shader Graphs/BlockPreview_Graph/Pass"
    25.  
    26.     }
    27.  
    28. }
    I don't really know much about ShaderLab so I haven't been able to make this work. Any help would be much appreciated.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,821
    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.
     
  3. SonicBlue22

    SonicBlue22

    Joined:
    Sep 10, 2018
    Posts:
    3
    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
    .
     
  4. SonicBlue22

    SonicBlue22

    Joined:
    Sep 10, 2018
    Posts:
    3
    This works!
    upload_2019-12-19_8-35-15.png
     
    Mehrdad995 and chrismarch like this.
  5. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    448
    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.
     
    Last edited: Aug 1, 2020
  6. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    448
    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

    upload_2020-7-31_18-0-12.png
     
    usingtheirs and andrew-lukasik like this.