Search Unity

Shader not receiving shadows

Discussion in 'Shaders' started by Cjmarkham, Aug 4, 2014.

  1. Cjmarkham

    Cjmarkham

    Joined:
    May 30, 2014
    Posts:
    41
    My custom shader doesn't receive shadows. I don't really know a lot regarding this code, I found a masking example and modified it to support more than 2 textures. Does anyone know where I have gone wrong?

    Code (CSharp):
    1. Shader "MaskedTexture"
    2. {
    3.    Properties
    4.    {
    5.       _MainTex ("Main Texture", 2D) = "white" {}
    6.       _cliffMask ("Cliff Mask", 2D) = "white" {}
    7.       _cliff ("Cliff Texture", 2D) = "white" {}
    8.       _sandMask ("Sand Mask", 2D) = "white" {}
    9.       _sand ("Sand Texture", 2D) = "white" {}
    10.       _otherMask ("Other Mask", 2D) = "white" {}
    11.       _other ("Other Texture", 2D) = "white" {}
    12.       _Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
    13.    }
    14.    SubShader
    15.    {
    16.       Tags {"Queue"="Geometry" "RenderType"="Opaque" }
    17.       Lighting Off
    18.       ZWrite On
    19.       AlphaTest GEqual [_Cutoff]
    20.      
    21.       Pass
    22.       {
    23.           SetTexture [_MainTex] {combine texture}
    24.       }
    25.       Pass
    26.       {
    27.          Blend SrcAlpha OneMinusSrcAlpha
    28.          SetTexture [_cliff] {combine texture, previous}
    29.          SetTexture [_cliffMask] {combine previous, texture}
    30.       }
    31.       Pass
    32.       {
    33.          Blend SrcAlpha OneMinusSrcAlpha
    34.          SetTexture [_sand] {combine texture, previous}
    35.          SetTexture [_sandMask] {combine previous, texture}
    36.       }
    37.       Pass
    38.       {
    39.          Blend SrcAlpha OneMinusSrcAlpha
    40.          SetTexture [_other] {combine texture, previous}
    41.          SetTexture [_otherMask] {combine previous, texture}
    42.       }
    43.      
    44.    }
    45. }
     
  2. Cjmarkham

    Cjmarkham

    Joined:
    May 30, 2014
    Posts:
    41
    Is this something really easy? Or have I done it completely wrong?
     
  3. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    After line 15 add somewhere this line:

    Code (csharp):
    1. Fallback "Diffuse"
    ..without the "1." The standard shader should then get picked up for the ShadowCaster and ShadowCollector passes that are required for shadows but missing in your shader. That'll be fine for all shaders that don't modify vertices; yours doesn't seem to.
     
  4. Cjmarkham

    Cjmarkham

    Joined:
    May 30, 2014
    Posts:
    41
    I added that line to the end of the sub shader (line 43) and I got a syntax error on that line. I have tried to use the fallback outside of the sub shader (line 44) but didn't get any shadows (no errors though).