Adding Shadow to my Shader Problem

Hey :slight_smile:

so ive got this shader;

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Unlit/CutoutShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Color ("Color", Color) = (1,1,1,1)
        _vtx0("pnt0", Vector) = (0,0,0,0)
        _vtx1("pnt1", Vector) = (0,0,0,0)
        _vtx2("pnt2", Vector) = (0,0,0,0)
        _vtx3("pnt3", Vector) = (0,0,0,0)
        _dbg ("Debug Dots", Float) = 0
    }
    SubShader
    {

    Tags {"Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout"}
        LOD 100
        Lighting On
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                float4 lsPos : TEXCOORD1;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _Color;
            float4 _vtx0;
            float4 _vtx1;
            float4 _vtx2;
            float4 _vtx3;
            float _dbg;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);//UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.lsPos = v.vertex;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                float2 dst0 = i.lsPos - _vtx0;
                float2 dst1 = i.lsPos - _vtx1;
                float2 dst2 = i.lsPos - _vtx2;
                float2 dst3 = i.lsPos - _vtx3;
                float2 edg0 = _vtx1 - _vtx0;
                float2 edg1 = _vtx2 - _vtx1;
                float2 edg2 = _vtx3 - _vtx2;
                float2 edg3 = _vtx0 - _vtx3;
                float2 nrm0 = float2(edg0.y, -edg0.x);
                float2 nrm1 = float2(edg1.y, -edg1.x);
                float2 nrm2 = float2(edg2.y, -edg2.x);
                float2 nrm3 = float2(edg3.y, -edg3.x);

                float alpha = max(
                    max(dot(nrm0, dst0) *22, dot(nrm1, dst1) * 22),
                    max(dot(nrm2, dst2) *22, dot(nrm3, dst3) * 22));

                fixed4 col = tex2D(_MainTex, i.uv) * _Color;
                fixed4 indic = fixed4(0,0,0,1);
                indic.x = max(step(length(dst0), _dbg), step(length(dst1), _dbg));
                indic.y = max(step(length(dst2), _dbg), step(length(dst3), _dbg));
                indic.z = max(step(length(dst3), _dbg), step(length(dst1), _dbg));
               
                clip(alpha);
                return lerp(col, indic,max(indic.x,indic.y));
            }
            ENDCG
        }
    }
}

And i am currently stuggeling to add in shadows/make it not unlit. this is how it looks like:

Can anyone tell me how can i change the shader to receive/drop shadows?
thanks!

If you want to support lighting in your shader, and you’re using the built in renderer, you’ll most likely want to look into using Surface Shaders.