Search Unity

Normal map not working when adding Standard in Always Included Shaders

Discussion in 'Shaders' started by kevin-masson, Dec 10, 2018.

  1. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    If i add Standard Shader in Graphic Settings > Always Included Shaders the normal map is not working properly and lighting fails (shadows, etc...) on WebGL.

    The problem occurs with WebGL builds and does not occur with standalone builds. Tested with Unity 2018.2.14f1. It happens in both Firefox and Chrome. The problem also occurs if the normal map is in the Secondary Maps.

    Video showing the bug:


    Video showing expected result:


    I need the Standard Shader in Always Included Shaders because I want to do Variant Stripping (note that I'm not stripping anything in this scene, I created it for test purpose because I noticed the bug while writing a stripper).

    I wrote a shader to display only the normal map, world normals and lambert coefficient and everything works correctly. I guess the problem must come from the standard shader.

    Maybe I'm missing something about variants but I haven't noticed anything relevant in the docs and online.

    Here is the unity scene reproducing the bug:
    https://www.dropbox.com/s/s8kjupajqppjf2c/WebGLNormalMapBug.unitypackage?dl=1
    (Don't forget to add Standard in Graphic Settings > Always Included Shaders to reproduce the bug).

    Here is my settings:

     
  2. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    The bug doesn't show up when using the Lightweight Rendering Pipeline.
     
  3. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    I think this should be added to the issue tracker.
     
    Twyker_gp likes this.
  4. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    Nobody else encountered this issue ?
     
  5. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    The bug also appears with different shaders like "Standard (Specular Setup)" or "Mobile/Bumped Diffuse (1 directional light)".
    I suppose it is a normal map bug, when I see the code that extract the normal in "Mobile/Bumped Diffuse", I'm wondering why the normal isn't being transformed before being used for lighting.
    Code (JavaScript):
    1.  
    2. o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTex));
    3. ...
    4. inline fixed3 UnpackNormal(fixed4 packednormal)
    5. {
    6. #if defined(UNITY_NO_DXT5nm)
    7.     return packednormal.xyz * 2 - 1;
    8. #else
    9.     return UnpackNormalmapRGorAG(packednormal);
    10. #endif
    11. }
    But that doesn't makes sense because the bug doesn't appear when the shader isn't in "Always Included Shaders", which shouldn't affect the code. Moreover, I have extracted the list of variants that are being compiled in both case and lists are identical.
     
  6. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
  7. TheZkip

    TheZkip

    Joined:
    Feb 21, 2013
    Posts:
    3
    Hi, we've been having a similar issue with normals on WebGL except in our case they break when we put the shader (and the objects that want to use that shader) in an asset bundle. The shader in question is not included in the 'Always Included shaders' list. Now, if we override the UnpackNormal function from above with a version that always calls UnpackNormalmapRGorAG (and doesn't care about the define) and put that in the asset bundle everything works and shading looks correct.

    I tried to build with shader variant stripping disabled from graphics settings (and without the override in the shader) but that results into broken shading as well.

    So, I'm thinking here that something that is same for the 'Always Included Shaders' list and asset bundles is causing 'UNITY_NO_DXTnm' to be defined which is not the correct behaviour for the shader on WebGL.
     
    Twyker_gp, KasperSP and kevin-masson like this.
  8. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    36
    Really weird things are happening with this 'Always Included Shaders' list...
     
    KasperSP likes this.
  9. KasperSP

    KasperSP

    Joined:
    Mar 7, 2017
    Posts:
    4
    You guys just saved my day :)

    [EDIT]: To clarify what we did to solve our issue (since I had a few PMs): We simply called UnpackNormalmapRGorAG() instead of UnpackNormal(). This way we're skipping the UNITY_NO_DXTnm check.
     
    Last edited: Sep 14, 2019 at 11:55 AM
  10. Twyker_gp

    Twyker_gp

    Joined:
    Dec 4, 2018
    Posts:
    9
    We are having the same problem, even with asset bundles that were built with the addressable asset system.
    Wrongly putting the normal maps into "default" format instead of normal maps also seems to help with this issue, but is by no means a fix obviously.