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

Help Please, Make this Behind Wall Shader in the Built In Render Pipeline.

Discussion in 'Shaders' started by h0neyfr0g, Jan 23, 2020.

  1. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    Hello everyone! Hope your day is going well.

    I would very much appreciate help recreating the same effect found here:


    I have been able to reproduce the effect, and it works perfectly. However, Brackeys solution uses the LWRP and my project's needs require the Built In Render Pipeline, so I am reverting back from LWRP to the Built In.

    I have tried scoured the internet and used many suggested Shader Codes but they all share the same problem, being that my Player Model is made up of multiple meshes with different textures. So when I use a Shader that involves the use of Z depth or the like, my Player Model's pieces occlude parts of itself (the head will be "in front" of the body, resulting in the body having shaded artifacts).

    I am really struggling to find the solution and would greatly appreciate your help solving it with me.

    Thanks very much
     
  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    demo_0000056.jpg
    You can try to setup this like on the above image:
    - Player materials (red, orange) write stencil mask 1 (comp: always, op: replace) and share the opaque queue.
    - Occluder materials (blue, navy) increment stencil mask (comp:always, op: increment) and share the opaque + 1 queue.
    - Player has also got a second overlay material with ztest: greaterEqual and stencil pass (ref: 2, comp: less equal, op: zero)
     
    h0neyfr0g likes this.
  3. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    Thank you very much for posting! I unfortunately am not versed well enough in shaders to understand completely. It looks like this process tells certain materials to ztest, while others do not? Would you mind explaining a bit further?
    Again, thanks a lot for helping!
     
  4. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    The standard action is to perform less or equal z-test, i.e. draw pixels if object is closer to camera than objects already drawn, otherwise hide.
    In case of overlay material we need them to be drawn ignoring the occluders.
    Here are the two shaders used in this scene.
     

    Attached Files:

    h0neyfr0g likes this.
  5. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    Im very grateful for your help! I'll try to implement this when I get off from work. I'm very interested in furthering my knowledge on how shaders work. I've got much to learn.

    Thanks again! its nice to find help.
     
    tomekkie2 likes this.
  6. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
  7. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    Hi buddy!
    So I think Ive got it set up correctly to a point. I just dont know how to make a second overlay material for my objects and add the Ztest shader to the materials. How would I do that?

    As of now, My player draws above everything else, but I cant make them appear another color behind the walls.

    Thanks for the help!

    ***EDIT***
    Hey bud, would you mind linking me your demo file? I've spend the last 10 hours trying everything i could to no avail :(
     
    Last edited: Jan 26, 2020
  8. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    So many variables, the key issue is to setup everything properly.
    Seems to work in my isolated objects scene, interesting if will work in your scene.

    materials.png
     

    Attached Files:

    h0neyfr0g likes this.
  9. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    It works! Thanks so much!
    But one last question.. I was incorporating Normal Maps on my materials... There doesnt seem to be an option for them anymore. The only thing I can think of is to double the geometry of the environment but that doesnt seem like a good idea. How would you go about adding back Normal maps to these materials?

    Thanks so much!!

    ***EDIT***

    I was able to modify the shader code to include Bump Maps!

    Thanks so much for your help! This was a huge hurdle/checkpoint for my project!
     
    Last edited: Jan 26, 2020
    tomekkie2 likes this.