Search Unity

UsePass Does Not Work With Differed Rendering

Discussion in 'Shaders' started by RobertBG, Apr 13, 2014.

  1. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    I have a fairly standard bumped surface shader that uses a pass of a fragment shader. It works perfectly in forward rendering but seems to ignore the pass in deferred rendering... Is this for real? Can you not use 'UsePass' in deferred rendering? I have even tested the frag shader on its own in deferred and it works fine.
     
    Last edited: Apr 13, 2014
  2. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
  3. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    Anyone had this problem? Seems like a pretty big one to me. :S
     
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Please don't bump your post every 2 hours. There's not that many people answering questions here.

    To figure out why UsePass doesn't work the way you expect it to, consider the way Deferred Lighting works, using multiple passes. When you write a surface shader, these passes are created for you.
     
  5. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    Hm. Are you saying there's no way to pass a frag shader over a surface shader? That seems incredibly limiting.. Theres got to be a way to do it. It even works if you add 2 materials to the same object, the first being the surface, and the second being the frag, isn't that technically doing the same thing as usepass? It just doesn't make sense why it wouldn't work..
     
  6. IronMathbook

    IronMathbook

    Joined:
    Apr 12, 2014
    Posts:
    60
    I'm curious about this too.
     
  7. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    No, I'm just indicating why it might not work in the way you expected. I haven't tried it myself, so I can't give you any specific advice right now. I know it's possible to add extra passes to Surface shaders, so you could try that first, and the replace it with 'UsePass' when it works.
     
  8. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    Yes I have seen this thread. I have done a lot of research on this. Yes everything they are doing will work... In forward rendering.... I have added extra passes of other surface shaders(Only works if you place the other surface shader in the same script, cause basically 'UsePass' seems completely dis-functional). But frag shaders is where it doesn't seem to work.
     
  9. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    If it only works with passes of other surface shaders, then perhaps you need to set up the Lighting Mode tag for it to work with custom vertex+fragment shaders.
     
  10. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    Hm, interesting. Works in deferred rendering when I use "PrepassFinal". But then it doesn't work in forward. How do I check if the lighting path is deferred or forward so I can do a multi-compile of the 2?
     
  11. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Exactly with those lightmode tags. The ones containing the word 'Prepass' indicate a pass should be used for Deferred Lighting.

    You could try using multiple LightMode tags. Does it work with 'Always'?

    Alternatively, you could put all your Cg shader code in a CGINCLUDE (...code here...) ENDCG block, and have multiple Pass blocks later in the file for each of the LightModes. The contents of the block should automatically be copied into each CGPROGRAM block during compilation, so you don't need to have any duplicate code.
     
    Last edited: Apr 14, 2014
  12. RobertBG

    RobertBG

    Joined:
    Apr 11, 2014
    Posts:
    15
    Hey, yes I will figure something out here :) Thank you very much for the help!