Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Multipass shaders in URP

Discussion in 'Shaders' started by jRocket, Apr 9, 2020.

  1. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    In the classic pipeline, one could write a shader that could have multiple passes- and each pass would be rendered in-order(as least in transparent queue). I need to do something similar in URP. I have seen the custom render passes, but it looks like you can only insert them at specific points in the pipeline- but I need these passes to render whenever the object will render.

    Example
    Object 1 Pass 1
    Object 1 Pass 2
    Object 2 Pass 1
    Object 2 Pass 2

    Whereas custom passes will give me
    Object 1 Pass 1
    Object 2 Pass 1
    Object 1 Pass 2
    Object 2 Pass 2

    Any idea how I could go about going something like this? I am trying to do traditional object outlines/silhouette(with zwrite off), but I need them to be sorted.
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    I use the renderer features thing. It lets you control shader passes visually, does this help? It's a core feature of URP. You add a forward renderer and then control stencil/passes/etc when you want them to be drawn.
     
  3. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    That's what I was looking at, but as far as I can tell, you can't have it draw something right after or before another object is drawn. You have to do them in passes.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    I do this for stencil portals, basically just abuse layers and remove the layer for sorted objects from the default list of objects to render, then you can fine grain it.
     
  5. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    Okay, I could make separate render features for each object I want to do this to- but then, if I am understanding you correctly, I would need different layers for each object. And I am limited to <32 layers. :(

    Is there a way to tell a render feature to just use a particular Renderer instead of filtering by a Layer Mask?
     
  6. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    277
    Impossible. Not only in URP itself, but in any custom SRP. You only option is using multi-materials.
     
  7. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    Do you mean by multi-materials? Where some triangles of an object have different materials? In my case, I need the entire SkinnedMeshRenderer to render twice, one after another. I thought about adding a second SkinnedMeshRenderer to a child GameObject, but I think that would inefficient as the skinning would get evaluated twice, probably isn't guaranteed to render in-order, and it adds complexity.
     
  8. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    Here is the effect I am going for, which was pretty simple to make in the classic pipeline with multipass shaders-



    Is this really impossible to do in URP, or any scriptable pipeline? If so, why it URP more limiting than the classic pipeline? I thought it was supposed to be production-ready.
     
  9. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    277


    No, there is no such functionality in SRP api.

    Marketing, nothing personal.
     
    Elfstone and Torbach78 like this.
  10. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    548
    That looked promising, but I just tested it and it doesn't render them in-order. It will render all objects with pass 1 and then render all objects of pass 2, just like using the render feature. :confused:
    I'll try to see if I can manually render these objects out with a command buffer.
     
  11. scotthNM

    scotthNM

    Joined:
    Apr 17, 2015
    Posts:
    4
    Hang on. if multi-pass shaders don't work anymore, how do we do meta passes for lightmap support?
     
  12. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    277
  13. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    445
    Sorry if late to the party, but since I'm here...
    You don't need a layer per object, if the effect is the same. For instance you can do the outline pass on multiple characters if they are using the same outline effect, with just one pass.

    Hope it helps!
     
  14. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    How can I use 2pass to make a transparent expression considering depth?
    In other words, it is a transparent expression like the left side of the attached image.
     
  15. comomomo

    comomomo

    Joined:
    Feb 16, 2014
    Posts:
    9

    Hi kkrg001! I'm trying to figure the same thing out but having trouble passing multiple textures through passes.

    Here's a link to a thread you might find helpful for your issue: https://forum.unity.com/threads/question-about-transparency-and-rear-faces.774224/#post-5213051

    It was nice when I could write a custom pass and it would just grab the maintexture from the model it was rendering. I'm not clear on how to do something similar in this pipeline without adding more passes.
     
  16. chavalo

    chavalo

    Joined:
    Feb 1, 2020
    Posts:
    1
    Hey. I ran into some issues with multi-pass shaders using URP too. I made a repository in which I tried my best to explain all the solutions I found to this problem. Some solutions are already in this thread, but I hope that having a project with all the examples will be more straightforward to understand.

    And I know this thread isn't recent, but it will hopefully help some people who stumble upon this thread in search of a solution like I did many times. :D

    https://github.com/chavaloart/
     
unityunity