Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug UsePass cannot reference passes within another shader's second subshader

Discussion in 'Shaders' started by RINNUXEI, May 18, 2023.

  1. RINNUXEI

    RINNUXEI

    Joined:
    Sep 3, 2015
    Posts:
    32
    Hey, we found a problem that UsePass cannot reference passes within another shader's second subshader. In our project, we use RenderPipeline tag to switch between the built-in render pipeline and our own custom render pipeline. However, if I use UsePass to reference a pass in another shader, it seems it only checks the first subshader in that shader, and if the first subshader does not contain the named pass, it won't check the second shader even if it's a compatible subshader (actually the first subshader's RenderPipeline tag does not match current globalRenderPipeline string, which is weird).

    Code (CSharp):
    1. Shader/MyShader1
    2. {
    3.     SubShader
    4.     {
    5.         Tags
    6.         {
    7.             "RenderPipeline" = "CustomPipeline"
    8.         }
    9.     }
    10.  
    11.     SubShader
    12.     {
    13.         UsePass "Shader/MyShader2/MYPASS"
    14.     }
    15. }
    16.  
    17. Shader/MyShader2
    18. {
    19.     SubShader
    20.     {
    21.         Tags
    22.         {
    23.             "RenderPipeline" = "CustomPipeline"
    24.         }
    25.     }
    26.  
    27.     SubShader
    28.     {
    29.         Pass
    30.         {
    31.             name MyPass
    32.         }
    33.     }
    34. }
    In the above code, when set Shader.globalRenderPipeline = "", which should activate the second subshader, but MyShader1 cannot render correctly due to UsePass cannot pull in MYPASS within MyShader2's second subshader. If I delete the first subshader within MyShader2, or copy MyPass into the first subshader, MyShader1 can render correctly. How can I reference a pass in a specific subshader or am I missing something here?

    I'm using Unity 2021.3.19f1 btw.

    Any help will be appreciated.
    Thank you!
     
    Last edited: May 19, 2023
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Hi!
    UsePass doesn't (and shouldn't) care about render pipelines.
    Please report a bug - I think it should work.
    Thanks!
     
  3. RINNUXEI

    RINNUXEI

    Joined:
    Sep 3, 2015
    Posts:
    32
    Thank you for your reply!
    I have sent a report containing a reproducible project (IN-41636). I hope you will take a look at it soon.
     
    aleksandrk likes this.