Search Unity

Resolved Model (and sky) turns black after adding a Normal Map

Discussion in 'Shader Graph' started by carcasanchez, Feb 5, 2020.

  1. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    27
    Hello,
    I am working with a shader that picks textures from an array. The diffuse channel works perfectly, but after adding a normal map, things start to go wrong.

    As you can see, the preview in ShaderGraph work as intended
    upload_2020-2-5_12-36-5.png

    But when I add the normal:
    upload_2020-2-5_12-37-1.png

    Strangely, when I turn to unlit mode, It can be seen that the normal map is properly placed and affecting the geometry:
    upload_2020-2-5_12-38-6.png

    Is this a bug, or there's some setting I forgot to tweak somewhere?
    (I am working with the latest HDRP and Shader Graph versions, Unity 2019.3)
     
  2. LandonTownsend

    LandonTownsend

    Unity Technologies

    Joined:
    Aug 21, 2019
    Posts:
    24
    The HD Lit node will attempt to normalize vectors passed into the "normal" input. Normalizing a 0 vector (which results from the black pixels in your normal map) will result in a divide by zero, resulting in NAN values. NAN values in HDRP propagate to the post processing, causing everything to render black when they're on screen.

    To solve this issue, make sure there are no black pixels in your normal map.

    As an additional note, you need to unpack normal maps in order to get the proper value to plug into the master node. Sample Texture 2D has a feature to do this (setting Type to "Normal") but Sample Texture 2D Array doesn't. Make sure to route the output of the Sample Texture 2D Array through a "Normal Unpack" node to get proper results.
     
    Last edited: Feb 6, 2020
  3. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    27
    Thanks for the help. I found that, If I apply the transparency at the same time as the unpacked normals (since the black part in the normal map is the same as the transparent part in the diffuse), it prevents the NaN value and works properly.
     
unityunity