Search Unity

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:
    12,352
    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
  5. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    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:
    472
    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.
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,362
    Hi,

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

    Thanks
     
    morepixels likes this.
  8. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    108
    Any update on this issue...?
     
    BOBchasing likes this.
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It's an intentional limitation. One that is unlikely to be fixed.
     
    BOBchasing likes this.
  10. qiyugaga

    qiyugaga

    Joined:
    Jun 15, 2019
    Posts:
    1
    Last edited: May 22, 2023