Search Unity

Adding shadows to a shader

Discussion in 'Shaders' started by Risine, Oct 28, 2020.

  1. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Hi everyone,

    I have a simple grayscale shader, which does not receive shadows.
    I've tried a few solutions I found with no success.
    Does someone know how my shader can take into account shadows?

    Here it is :
    Code (CSharp):
    1. Shader "Custom/GreyScale" {
    2.     Properties{
    3.         _MainTex("Texture", 2D) = "white" { }
    4.         _Factor("Factor", Range(0, 1.0)) = 0.6
    5.     }
    6.         SubShader{
    7.             Tags { "RenderType" = "Opaque" }
    8.             LOD 150
    9.             Pass {
    10.  
    11.         CGPROGRAM
    12.         #pragma vertex vert
    13.         #pragma fragment frag
    14.  
    15.         #include "UnityCG.cginc"
    16.  
    17.         sampler2D _MainTex;
    18.         float _Factor;
    19.  
    20.         struct v2f {
    21.             float4  pos : SV_POSITION;
    22.             float2  uv : TEXCOORD0;
    23.         };
    24.  
    25.         float4 _MainTex_ST;
    26.  
    27.         v2f vert(appdata_base v)
    28.         {
    29.             v2f o;
    30.             o.pos = UnityObjectToClipPos(v.vertex);
    31.             o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    32.             return o;
    33.         }
    34.  
    35.         half4 frag(v2f i) : COLOR
    36.         {
    37.             half4 texcol = tex2D(_MainTex, i.uv);
    38.             texcol.rgb = dot(texcol.rgb, float3(0.3, 0.59, 0.11)) * _Factor;
    39.             return texcol;
    40.         }
    41.         ENDCG
    42.  
    43.             }
    44.     }
    45.         Fallback "Diffuse"
    46. }
    Thanks
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553