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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question multi-pass shader solution for URP? (fur shader)

Discussion in 'Universal Render Pipeline' started by MMeyers23, Jun 23, 2020.

  1. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    Hi,

    After reading some popular (but outdated) articles (see https://www.alanzucconi.com/2015/06/28/fur-shading-in-unity3d/) about writing custom fur shaders I realized that the multi pass functionality they use is not possible in URP, at least not on the same level, since URP does not support writing multiple passes in a shader.

    Could someone point me to a solution in URP? There must be a way to make a simple shader like this in URP, right?
     
    LoloSpirit likes this.
  2. actuallystarky

    actuallystarky

    Joined:
    Jul 12, 2010
    Posts:
    188
    I have the same issue. I've written a simple fur shader that uses 12 passes of progressively alpha'ed geometry and I have no idea how I can port this to the URP.

    The best I can think of is to add a 12 custom render passes but that will have draw order issues as layer 1 for all objects will be rendered, then layer 2 etc. I suppose it would be okay if I switched from alpha blend to alpha test and wrote to the z-buffer but the soft edge is a big appeal of the effect. Even then I'm not sure if 12 custom render passes will work.

    Are there any solutions for this effect in URP or is it simply not possible?
     
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    629
    If you add 2 or more materials to a mesh renderer with one submesh, the mesh will be rendered multiple times, one with each material, I think this behaviour still exists in URP?

    Not sure there's any guarantees about draw order though...
     
  4. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    looks like the the old shell method is the only option, as far as I am aware. Like bluescrn mentioned, using multiple materials on a mesh rendered with each material having a different alpha cut off, google shell or 'cards' method if you dont know already about this method of faking fur, grass, etc.
     
  5. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    I make fur manually, with BatchRendererGroup api. Think it's most efficient way to do this kind of stuff.
     
  6. actuallystarky

    actuallystarky

    Joined:
    Jul 12, 2010
    Posts:
    188
    Thanks everyone for the replies!

    In the old standard renderer, the fur effect is achieved with the one multi-pass shader. I don't know for sure but using 12 materials sounds a lot slower. I guess the fur layers can all use the same shader with a different fur offset value. I'll test and see.

    @BattleAngelAlita I haven't used the BatchRendererGroup api before but I don't think it would be useful in this case - I could be wrong. My foliage has a very stylised look using shells of progressively offset and alpha'ed geometry. This image here -
    upload_2020-12-8_15-55-4.png
    is produced with a simple shader applied to this geo
    upload_2020-12-8_15-56-22.png
     
    detective-vr likes this.
  7. actuallystarky

    actuallystarky

    Joined:
    Jul 12, 2010
    Posts:
    188
    Hello! I did indeed get this working in the URP by adding multiple materials to the one object. It feels hacky and is a lot more setup than the old version but it does work.
    upload_2021-1-27_16-39-0.png

    You do have to make sure that your "grass" material is the last material on the list. This is determined upon export so it can be tricky to control this. I had to break apart the object and attach the pieces in a specific order to get the materials importing how I wanted.

    You could do this effect far cleaner and probably faster using geometry or compute shaders but I've stayed away from both due to concerns with the iPhone / Mac platforms which seem to be a bit of a mess in this regard.
    upload_2021-1-27_16-38-11.png
     
    detective-vr and deus0 like this.