Search Unity

Custom Standard shader isn't receiving shadows.

Discussion in 'Shaders' started by WDudderz, Mar 9, 2017.

  1. WDudderz

    WDudderz

    Joined:
    Apr 6, 2013
    Posts:
    12
    Hi folks,

    Sorry if this gets posted all the time, but I couldn't find an answer specific to this.

    I've created a quick shader based on the Standard Specular as I needed 2 sided rendering, but it's not receiving shadows for some reason. Any ideas what I'm missing?

    Code (csharp):
    1. Shader "Standard (2 Sided)" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGBA)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Specular ("Specular Color", Color) = (0,0,0)
    7.         _Cutoff ("Cutoff", Range(0,1)) = 0.5
    8.     }
    9.  
    10.     SubShader {
    11.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    12.         LOD 200
    13.         Blend SrcAlpha OneMinusSrcAlpha
    14.         Cull Off
    15.        
    16.        
    17.         CGPROGRAM
    18.         #pragma surface surf StandardSpecular alpha:fade fullforwardshadows
    19.         #pragma target 3.0
    20.  
    21.         sampler2D _MainTex;
    22.  
    23.         struct Input {
    24.             float2 uv_MainTex;
    25.         };
    26.  
    27.         half _Glossiness;
    28.         fixed3 _Specular;
    29.         float _Cutoff;
    30.         fixed4 _Color;
    31.  
    32.         void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
    33.             // Albedo comes from a texture tinted by color
    34.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
    35.             o.Albedo = c.rgb;
    36.             // Metallic and smoothness come from slider variables
    37.            
    38.            
    39.             if (c.a > _Cutoff) {
    40.                    o.Alpha = c.a;
    41.                 o.Specular = _Specular;
    42.                 o.Smoothness = _Glossiness;
    43.                    }
    44.              else
    45.              {
    46.                    o.Alpha = 0;
    47.                    }
    48.         }
    49.         ENDCG
    50.     }
    51.     FallBack "Standard"
    52. }
    Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    In Unity shaders using the transparent queue don't receive shadows.