Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Incorrect shadows with custom shader in Unity 5

Discussion in 'Shaders' started by Jaimi, Mar 11, 2015.

  1. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,169
    I have a shader that I wrote for character customization. This shader worked fine in Unity 4. And it works fine in Unity 5 with one exception... The shadows that are cast from it are wrong - light shines through in spots that follow certain parts of the texture/model:

    WonkyShadows.png

    This is even worse with the shadow texture resolution is lower:

    Wonky2.png

    It doesn't appear to have anything to do with the texture, as a cube with the standard shader and texture looks correct.

    The shader is defined opaque, but I always thought the shadow would be cast with a dummy material anyway. Is that no longer the case?

    The shader is defined like this:

    Shader"Custom/CharShader" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _MaskTex ("MaskTex (RGBA)", 2D) = "black" {}
    _EyeColor ("EyeColor", Color) = (0.5,0.5,0.5,1)
    _SkinColor ("SkinColor", Color) = (0.5,0.5,0.5,1)
    _HairColor ("HairColor", Color) = (0.5,0.5,0.5,1)
    _AccentColor("AccentColor", Color) = (0.5,0.5,0.5,1)
    _LightFactor("LightingFactor",float) = 2.0
    _ShadeMult ("ShadeMult",float) = 0.5
    _ShadeAdd ("ShadeAdd",float ) = 0.5
    _AccentStrength ("AccentStrength",float) = 0.0
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    ... // shader itself deleted for brevity, but fallback is "diffuse".

    Any idea what could be causing this?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Seems like common artifacts seen in soft shadowing. I haven't looked at Unity 5 yet, but you might need to change some shadow settings on the light.
     
  3. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Set normal bias of light to 0.
     
  5. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Doesn't help for me
     
  6. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,169
    Ha! You were right, it wasn't the shader at all. Thanks!
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723