Search Unity

Question How can I implement Double-Sided normal modes in ShaderGraph for URP?

Discussion in 'Shader Graph' started by Ben_at_Work, May 26, 2022.

  1. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    I've been trying to improve my foliage shader to serve as a stop-gap while I identify a more performant option for a VR application, and I'm working on ways to address surface normal issues. One feature I encountered which might help is the Normal Mode which is actually listed in the HDRP docs for Shader Graph. For URP, however, I can't find a parallel option, just the standard toggle for enabling Double-Sided. Does it exist anywhere?

    There's a Is Front Facing node which gives me a usable mask in SG, but it's only available in the Fragment stage while a node based change would presumably need to be applied on the Vertex stage (?).

    I found code for it in an Amplify shader from The Vegetation Engine but the code is written very differently than SG so I can't readily copy-paste it without more instructions:

    [Enum(Flip,0,Mirror,1,Same,2)]_RenderNormals("Render Normals", Float) = 0


    The end goal is to make the leaves using my shader have less dramatic contrast from shading. They're big enough leaves that the mesh surface normals are usable, so I'm skipping the part where you bake from a soft mesh for now.
     
  2. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    My temporary solution was to add an emissive boost multiplier for each facing direction based on the switch. It's not ideal but it works for my particular situation at the moment. The ambient color is multiplied against the desired weight, then against the albedo color.

    ambientBoostPerFacingAngle.PNG

    I did at least find a similar solution for grass type foliage which switches the vertex normals to up (0,1,0) in the vertex stage. That saves me having to properly bake them out in a modeler and aligns grass meshes salvaged from elsewhere.
     
  3. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    It's also worth noting that Unity normal maps should be in right-handed OpenGL (Y+) orientation. I had an export from Substance Painter which was exported in the opposite orientation that contributed to the normal map issues I was having. Unfortunately it didn't account for enough to eliminate the original obstacle.