Search Unity

Question Shader Graph - Lighting Back Face

Discussion in 'Shaders' started by LtStudley, Jun 24, 2020.

  1. LtStudley

    LtStudley

    Joined:
    Dec 28, 2018
    Posts:
    2
    Hi everyone,

    I'm very new to working on shaders, so thanks in advance for the help. I am trying to make a shader for trees/grass, for which I need both sides of the leaves (which are planes) to be rendered and lit. However, setting the master node to "Two Sided" does not light the back face.

    I've done a lot of research online, and there are many options, such as duplicating and flipping the planes, using VFACE to render both sides in one pass, etc. However, I am having a lot of trouble figuring out how to do this in the shader graph. I've tried many things that I've found online, to no avail. Any help will be greatly appreciated!

    I should also mention that I need the shader to support transparency. As you can see from the screenshot, the back face of the plane is not being lit.
     

    Attached Files:

  2. Namey5

    Namey5

    Joined:
    Jul 5, 2013
    Posts:
    188
    You need to flip the vertex normals if the camera is looking at the back of the mesh;

    upload_2020-6-25_11-46-40.png

    Annoyingly there is a bug where you can't use the view direction node in a chain that leads to any vertex modifications, so we have to recreate it ourselves with the camera position. The matrix in use that's cut off is the Inverse Model matrix.
     
  3. LtStudley

    LtStudley

    Joined:
    Dec 28, 2018
    Posts:
    2
    Thank you for the reply! That seems to partially work, but the back face is still darker than the front.
     
  4. Namey5

    Namey5

    Joined:
    Jul 5, 2013
    Posts:
    188
    If you have shadows in your scene you will need to set the normal bias to 0 in your pipeline settings. It only shifts the shadowcaster vertices in the direction of the original vertex normals, thus pushing the shadows to always occlude on backfaces.
     
  5. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Hello friends, this is the solution that worked for me:

    upload_2020-9-11_6-7-35.png

    This appears to work without artifacts for any kind of geometry.
     
    leongsj, StaticWave, Binhou and 4 others like this.
  6. Gargosian

    Gargosian

    Joined:
    Sep 7, 2017
    Posts:
    8
    Good job on on the Graph! Addionally to changin the "Normal Bias" to 0 I also had to tick the "Soft Shadows" box right below, that did it for me!
    Thanks a lot
     
    FileThirteen likes this.
  7. LeonelAmaral

    LeonelAmaral

    Joined:
    Nov 3, 2018
    Posts:
    6
    How did you get that Is front Face node?
     
  8. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
  9. darkdoom973

    darkdoom973

    Joined:
    Jul 21, 2020
    Posts:
    13

    Hey I am using the shader graph, URP, and I enabled render both faces on plane type mesh, one side looks great but the other seems somewhat whitish, just wondering if you can help?
     
  10. NPCsZ

    NPCsZ

    Joined:
    Jul 5, 2017
    Posts:
    4
    I know this is 2022 and it's too late but your answer actually works thanks a lot.
     
    cxode likes this.
  11. LordCafe

    LordCafe

    Joined:
    Aug 26, 2015
    Posts:
    35
    Thank you for fixing unity poor job at making basic shaders like that... it's almost 2023 and we still have to fix something that should be default from such engine... since unreal in 2008 had this feature as BASIC shader setup... again, thank you for helping us.
     
  12. binarymaus

    binarymaus

    Joined:
    Mar 15, 2020
    Posts:
    2
    Big oof, for someone new to Shader Graphs this was a big issue (it's 2023 now ._.'). Thanks for the easy fix!
     
  13. MatheusDallaRT

    MatheusDallaRT

    Joined:
    Sep 15, 2021
    Posts:
    3
    Actually this way I`m having messy results with the SSAO with smooth shapes.
     
  14. korsynx

    korsynx

    Joined:
    Jan 2, 2021
    Posts:
    11
    None of these solutions are working in a lit shader graph in built-in. How can i render backfaces with correct normals? This option seems like it should be provided by unity
     
    Two_Click_Tools likes this.