Search Unity

Modifying previous passes in multi-pass surface shader

Discussion in 'Shaders' started by Warrior1424, Sep 3, 2017.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    I have a surface shader with 3 passes.
    On the final pass I would like to distort what the previous 2 passes have rendered with a normal map.
    The normal map distortion is not a problem, as there are many resources on the topic online.

    However, I cannot find how to grab previous passes within a surface shader.
    Is this even possible?
     
  2. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    357
    I don't believe that's possible due to the isolation of each pass. One solution (albeit at the expense of an additional pass) would be to insert a named GrabPass which could then be used as the input to the third. Something like this;
    Code (CSharp):
    1. Pass { FirstPass }
    2. Pass { SecondPass }
    3. GrabPass { "InputTex" }
    4. Pass { FourthPass, distort InputTex }
     
  3. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I would recommend using a CommandBuffer instead. For testing purposes a GrabPass is fine, but you're a lot more flexible when using a CommandBuffer. So render pass 1 and 2 into a RenderTexture at the right time using a CommandBuffer and render pass 3 in the normal way using the RenderTexture as input.
     
  4. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    357
    Indeed, that's the other solution. Although it's worth noting that GrabPass is perfectly fine for production purposes too! It doesn't quite add up to the cost of a regular pass as it merely blits to texture and makes it available to you. In-essence, it's the same approach, just less involved. :)