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?
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!
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.
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.
I’ve run into this problem as well (See request here https://discussions.unity.com/t/738722/16 ) 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.
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.
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.
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!