Search Unity

Normal Map Missing in Shadows

Discussion in 'Shaders' started by Nuclear-Arbitor, Mar 23, 2017.

  1. Nuclear-Arbitor

    Nuclear-Arbitor

    Joined:
    Mar 9, 2017
    Posts:
    3
    I'm working on a mobile game in unity 5.5.0. We're using the Mobile/Bumped Specular shader for our materials and the scene is lit by a single dynamic directional light. The issue is that the shader does not support normal mapping in shadows and the half of the scene in shadows looks terrible as a result.

    We're using the bumped specular shader for performance reasons but i haven't had the time to figure out profiling and actually profile a scene with the standard shader vs the bumped specular shader. does anyone know the performance difference (even approximately) between the mobile shader and the standard one? switching to the normal shader would be one way to solve the problem.

    the other option is to write a custom shader based upon the the mobile bumped shaderd that includes the standard shader's ability to render normal maps in shadows. i've looked at the two shaders but i don't know enough to figure out what i need to copy from standard and google hasn't been a help.

    Bumped Specular Shadows.png

    Bumped Specular vs Standard.png
     
    Last edited: Mar 24, 2017
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Normals adjust the normal of a surface for calculating lighting. So in no light, aka all shadow, you get no change.

    What you want is occlusion.
     
  3. Nuclear-Arbitor

    Nuclear-Arbitor

    Joined:
    Mar 9, 2017
    Posts:
    3
    that's part of the problem but i still get small highlights with the standard shader. (see original post)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The mobile shader does diffuse ambient lighting per vertex rather than per pixel. I believe the legacy diffuse bump (non-mobile) may do it post pixel, but it's possible it also only does per vertex ambient.

    The main change to get per pixel ambient lighting is look for the line with ShadeSH9 in the mobile shader, you'll find it in the vert function. You'll need to move that into the fragment shader, supplying the appropriate world normal as calculated in the fragment shader. That'll get you lighting in the shadows.

    However the standard shader additionally does per pixel ambient specular reflections. This I believe is what you're actually seeing and likely makes the most significant difference in appearance between the standard and mobile bumped shader, especial if you've got your editor set to emulate mobile graphics.
    https://docs.unity3d.com/Manual/GraphicsEmulation.html

    If you're looking to use that feature your better off just using the standard shader than trying to update the mobile shader, but those reflections are one of the more expensive parts of the shader for mobile (even though it's nearly free on desktop).
     
  5. Nuclear-Arbitor

    Nuclear-Arbitor

    Joined:
    Mar 9, 2017
    Posts:
    3
    so if i'm understanding you correctly, moving ShadeSH9 will change lighting to per pixel but that might not solve my issue. i'll try and move that line and see what the results are and i need to bite the bullet and do profiling.

    thank you.
     
  6. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    In this case you could also just fake it by adding the lighting you want to see in the shadow to the diffuse map. For desktop I would recommend adding some directional lightmaps, but for mobile this might just be the trick.