Search Unity

Question Normal construction

Discussion in 'Shader Graph' started by snacktime, Mar 4, 2021.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Need to verify some specific behavior with normals in SG. This is HDRP 10.x.

    My specific case is mesh vertices are heavily geo morphed in the vertex state. The mesh has no uvs or normals by design. Normal construction is by design per pixel with no relation to uvs imaginary or real.

    So what I need to know is that SG isn't going to transform the normals I hand it by some made up uv positions of some type. My fear is that it will. I actually have a shader using Better Shaders and that's what it's doing. So unless it's a BS bug my fear is this is just core to HDRP shaders and I'm going to have to solve this with a low level vert/frag custom pass setup.

    My guess is that HDRP shaders need the tangent space normals translated back to something else at some point, but it seems impossible that it would have a correct basis for doing so with per pixel normals.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I think what you're asking is if the normals you construct are going to be treated as tangent space normals or as object or world space normals. By default Shader Graph is going to treat the normals you pass to the master node as tangent space normals. But as of Shader Graph 10 it now exposes options to treat the graph's output normals as either tangent, object, or world space.

    As for Better Shaders, I'd ask @jbooth about this. There's no reason why it couldn't support object or world space normals as well. It likely already has the code to support it, or it wouldn't be too hard to add.
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Right now it assumes tangent- would be easy to add a world normal option, but you can also just use the WorldToTangent space function or mul(worldNormal, d.TBNMatrix) to convert back for now..
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    As @jbooth correctly pointed out to me on his discord I should be able to just swizzle y and z since the shader in question was a water shader. Plus the issue remained even when I converted to a low level vert/frag shader that calculates lighting directly so my specific issue is likely not actually normals. (example here https://forum.unity.com/threads/waveworks-2-in-unity.1069871/).
     
  5. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    What I didn't understand is the interaction with the mesh uv's. I fed in this case BS tangent space normals but let's assume BS is feeding the internal pipeline what SG would. Internally HDRP was using uvs somehow. I don't use uv's I just added some to the mesh to confirm the behavior, and sure enough they had an impact.