Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

LWRP & Shader Graph - How do render back faces?

Discussion in 'Graphics Experimental Previews' started by Matt-Cranktrain, May 2, 2019.

  1. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    132
    Hello! A hopefully straight-forward question, I've got a project with LWRP on Unity 2019.1, and I've got a shader I've made with Shader Graph. How do I add the ability for that shader to render back faces as well as the front ones?

    I notice if I create an object and add to it the default
    Lightweight Render Pipeline/Lit
    shader that comes with the project, there's a
    Render Face
    selection in the 'Surface Options' that lets me select
    Front
    ,
    Back 
    or
    Both
    .

    This works great and is exactly what I want!

    How do I replicate this functionality in Shader Graph?
     
    RomanArtiukh likes this.
  2. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    132
    I figured it out! Super-simple, when building your shader in Shader Graph, there's a little settings icon on the PBR Master node, select it and you can turn on "Two Sided", which renders back faces as well.

    I'm not sure why this isn't exposed on a per-material basis by parameter, like the Lit shader I mentioned in my original post, but that's okay!
     
  3. Smireles

    Smireles

    Joined:
    Jun 20, 2008
    Posts:
    38
    Something so simple, yet, I spent quite some time googling it. Thanks for sharing! @Matt-Cranktrain
     
    ZIMohammad and Matt-Cranktrain like this.
  4. Why485

    Why485

    Joined:
    Jun 30, 2013
    Posts:
    45
    I'd like to echo this sentiment. I'd like to have an option for a shader graph to be either single or two sided, but I don't see any way to do that without copying the entire shader over again, just with the two sided option being different. I checked to see if I could use the boolean keyword to help with this, but you can only have one active master node at a time and I don't think the boolean keyword can change that.

     
    Matt-Cranktrain likes this.
  5. gamecentric

    gamecentric

    Joined:
    Jan 4, 2019
    Posts:
    3
    Nice, but is there a way to draw only the back faces?
     
  6. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    132
    Drawing only the back faces requires, I assume, taking all the polygon normals and treating them as the inverse to what they are. Sorry, I don't know how that looks at the Shader Graph level, though it might be much easier than what I'm about to suggest.

    I have a very case-specific need in my game to, under certain situations, flip (and do other weird stuff with) the normals of a mesh at runtime. Rather than doing this at the shader level, I actually take the script+mesh approach, and this old script is a helpful reference if you're not used to fiddling about with meshes.
     
  7. lostminds

    lostminds

    Joined:
    Jan 17, 2019
    Posts:
    51
    I've run into this problem as well (See request here https://forum.unity.com/threads/features-i-would-want-to-see.658090/#post-5352549 ) and I'd like there to be a front / back / both sides selection in shader graph materials as well (instead of the current both / front)

    The method I've found to draw just back faces is a little convoluted, but works: Basically set the shader graph to be both sides, and then use the IsFrontFace node to check if it's a front face fragment. Connect that check to your alpha so that any front face fragments get alpha 0 and you should have a graph that renders only the back sides. Probably very inefficient, but it's the only way I've found using shader graph.

    Ideally, I'd like the "both" sides option to run two passes on the shader, one first for backsides and then one for front sides letting me use the IsFrontFace node to set up the shader to render both backsides and front sides, but making sure the front sides are always rendered on top of the backsides. Currently you can do this, but you need to make two shaders one for frontsides and one for backsides, then make a material each from them, assigning the backside one an earlier rendering priority and assigning both materials to the mesh. Would be so much nicer if it could be done in just one shadergraph shader.
     
    Matt-Liewer-AofL likes this.
  8. gamecentric

    gamecentric

    Joined:
    Jan 4, 2019
    Posts:
    3
    It can be a little unintuitive, but the front/back-face property does not depend on the normals, but rather on the order (clockwise or anti-clockwise) of the triangle vertices. Of course, if the mesh is properly set, the two computations usually coincide. Using the IsFrontFace as suggested by @lostminds is the correct way to check this property. Alas, I came to the same conclusions as @lostminds that you have to create two different shader graphs to handle both front faces and back faces and the latter must use double-face and cull front faces using alpha. Not very convenient.
     
    Florian-ppcr likes this.
  9. cpthindsight

    cpthindsight

    Joined:
    Feb 6, 2022
    Posts:
    7
    This property is now called 'Render Face' in new versions of Unity and can be found in the Graph Settings window. I'm using 2021.3.11f.
     

    Attached Files:

  10. Unity_Nitro

    Unity_Nitro

    Joined:
    Aug 27, 2022
    Posts:
    3
    I use Unity 2021.1 (haven’t gotten around to updating :/ ) and found a simple way by taking the “normal vector” node and multiplying it by negative one (different from inverting) and then plugging that into the vertex normal. Don’t forget that the node has to be Two Faced which I now find in the graph inspector under graph settings.
     
  11. sanliuk

    sanliuk

    Joined:
    Oct 1, 2022
    Posts:
    2
    HDRP does not have the option for two sides. (both)
    Ther's an option called double-Sided but it is not working actually.
    Did anyone find any solution for HDRP Shader graph?


    (Edit)

    I solved with hdrp.
    Double sided checked in the inspector of shader graph was exposed so I had to check it on the material too! If you do not check both it does not work. That's why!
     
    Last edited: Jan 20, 2024