平面阴影

Shader "Unlit/role"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "Queue" = "Transparent" "RenderType"="Transparent" }
        LOD 100
		Blend SrcAlpha OneMinusSrcAlpha
		Stencil{
			Ref 1
			ReadMask 1
			WriteMask 255
			Comp NotEqual
			Pass Replace
		}
        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;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
				float4 worldpos = mul(unity_ObjectToWorld, v.vertex);
				half3 lightdir = normalize(_WorldSpaceLightPos0.xyz);
				worldpos.xyz = float4(worldpos.x - worldpos.y*lightdir.x / lightdir.y, 0, worldpos.z - worldpos.y*lightdir.z / lightdir.y, 1.0);
				o.vertex = mul(unity_MatrixVP, worldpos);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return fixed4(0,0,0,0.3);
            }
            ENDCG
        }
    }
}

  写死了 投影在y = 0的平面

 

posted on 2019-12-06 10:09  marcher  阅读(131)  评论(0编辑  收藏  举报

导航