Search Unity

Shader cast but don't receive shadows

Discussion in 'Shaders' started by Daniel10, Oct 21, 2013.

  1. Daniel10

    Daniel10

    Joined:
    Aug 11, 2013
    Posts:
    10
    Hi!!

    I'm beginner in shaders... I'm trying to put a shadow in my shader. He will be on static objects and I cannot use lightmap.
    I got to cast shadows adding fallback and I've tried everything to make the model also receives shadows. Follow the code below, if anyone can help me would be very grateful. :D


    Code (csharp):
    1. Shader "stand colors" {
    2.  
    3. Properties {
    4.  
    5.     _Emission ("Emissive Color", Color) = (0,0,0,1)
    6.     _Correction ("Correction", Color) = (1,1,1,1)
    7.     _SpecColor ("Spec Color", Color) = (1,1,1,1)
    8.      
    9.    
    10.     _MaskColor1 ("MaskColor1", Color ) = (1,1,1,1)
    11.     _MaskColor2 ("MaskColor2", Color ) = (1,1,1,1)
    12.    
    13.     _MainTex ("Texture", 2D) = ""
    14.     _Mask1 ("Mask1", 2D) = ""
    15.     _Mask2 ("Mask2", 2D) = ""  
    16.    
    17. }
    18.  
    19. SubShader {
    20.    
    21.  
    22.    
    23.    Blend SrcAlpha OneMinusSrcAlpha
    24.    
    25.         Pass {
    26.        
    27.             Material {
    28.              
    29.                 Diffuse [_Correction]
    30.                 Specular [_SpecColor]
    31.                 Emission [_Emission]
    32.                
    33.             }
    34.            
    35.             Lighting On
    36.             SeparateSpecular On
    37.            
    38.             SetTexture[_MainTex]{
    39.                 constantColor [_Correction]
    40.                 Combine texture * constant
    41.             }
    42.                    
    43.                
    44.         }
    45.        
    46.            
    47.         Pass{
    48.        
    49.    
    50.             AlphaTest Greater 0.5
    51.          
    52.             Blend DstColor SrcColor                      
    53.          
    54.          
    55.             SetTexture[_Mask1] {
    56.            
    57.                 constantColor [_MaskColor1]
    58.                 Combine texture * constant
    59.            
    60.             }
    61.            
    62.                    
    63.         }
    64.            
    65.    
    66.            
    67.         Pass{
    68.        
    69.    
    70.             AlphaTest Greater 0.5
    71.          
    72.             Blend DstColor SrcColor                      
    73.      
    74.             SetTexture[_Mask2] {
    75.            
    76.                 constantColor [_MaskColor2]
    77.                 Combine texture * constant
    78.                
    79.             }
    80.                
    81.         }  
    82.                        
    83.     }
    84.    
    85.  
    86. Fallback "Diffuse"
    87.    
    88. }
    89.  
    90.  
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Fixed function shaders like this cannot receive shadows.