Search Unity

Resolved Normal Map Inverts During Object Rotation

Discussion in 'Shader Graph' started by Salmonman, Aug 21, 2019.

  1. Salmonman

    Salmonman

    Joined:
    Jul 14, 2016
    Posts:
    23
    I'm trying to make a very simple Toon Shader with normal maps, starting from the Unlit Graph, and I've worked out transforming my normals to world space and then taking the dot product of them with an arbitrary light direction vector, but for some reason the resulting light information seems to be getting reversed when the object is rotated.

    I don't know if I'm even doing the nodes right because I can't find any examples of custom unlit shaders that use normal maps.





    You can see how the lighting seems to rotate twice as far as the cube actually does.
     
  2. LandonTownsend

    LandonTownsend

    Unity Technologies

    Joined:
    Aug 21, 2019
    Posts:
    35
    I can't reproduce this issue. Can you post what version of unity you're using, as well as what version of shadergraph you have? Your node set up looks correct by the way, I'm getting correct results using the same set up.
     
    Last edited: Aug 21, 2019
  3. Salmonman

    Salmonman

    Joined:
    Jul 14, 2016
    Posts:
    23
    I'm using Unity 2019.2.0f1, and Lightweight RP version 6.9.1. I updated LWRP to try and fix it as well, thinking that might have been the problem, but I got the same results before and after the update.


    Perhaps this information could be of use. I've noticed an inconsistency. When I rotate the cube through the Z axis, the side that was previously facing up has now had it's normals inverted.


    But if I rotate it through the X axis, the side that was previously facing up began with upside down normals and retains those upside down normals.
     
    Last edited: Aug 21, 2019
  4. Salmonman

    Salmonman

    Joined:
    Jul 14, 2016
    Posts:
    23
    Ok I guess I actually answered my own question. The problem wasn't with my nodes or my versions, it was the normal map itself. The rotational inconsistency finally made the connection in my head, and it turns out that my Green channel is inverted. Multiplying it by -1 seems to fix all the issues.

    Thanks for the reply anyway.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    For future reference, your normal maps were exported with -Y format, or "Direct3D style". Unity uses +Y, or "OpenGL style" normal maps. Basically Direct3D tangent space normal maps look like they're being lit "from below" and OpenGL tangent space normal maps look like they're being lit "from above".
     
    whoisj likes this.