美文网首页
实时阴影

实时阴影

作者: OneMore2018 | 来源:发表于2018-11-08 12:10 被阅读7次

Shader "Custom/SingleShadow" {

    Properties {

        _MainTint ("Color", Color) = (1, 1, 1, 1)

        _LightDirection ("LightDirection", Vector) = (1, 1, 1, 1)

        _ShodowIntensity ("ShodowIntensity", float) = 1

    }

    // real shadow

    SubShader {

        Tags { "Queue"="Transparent" "RenderType"="Shadow" "IgnoreProjector"="True" }

        Pass {

            Lighting Off

            Cull Back

            ZTest LEqual

            ZWrite Off

            Offset -2, -2

            Blend SrcAlpha OneMinusSrcAlpha

            Stencil {

                Ref 64

                Comp Greater

                Pass Replace

            }

            CGPROGRAM

            #pragma vertex vert

            #pragma fragment frag

            #pragma fragmentoption ARB_precision_hint_fastest

            #include "UnityCG.cginc"

            fixed4 _MainTint;

            fixed4 _LightDirection;

            fixed _ShodowIntensity;

            struct v2f {

                half4  pos : SV_POSITION;

                half2  uv : TEXCOORD0;

            };

            v2f vert (appdata_base v)

            {

                v2f o;

                half4 worldPos = mul(unity_ObjectToWorld, v.vertex);

                worldPos.xyz = float3(worldPos.x - worldPos.y / _LightDirection.y * _LightDirection.x, 0, worldPos.z - worldPos.y / _LightDirection.y * _LightDirection.z);

                v.vertex = mul(unity_WorldToObject, worldPos);

                o.pos = UnityObjectToClipPos(v.vertex);

                return o;

            }

            fixed4 frag (v2f i) : COLOR

            {

                fixed4 outp = _MainTint;

                outp.a = _ShodowIntensity;

                return outp;

            }

            ENDCG

        }

    }

}

相关文章

网友评论

      本文标题:实时阴影

      本文链接:https://www.haomeiwen.com/subject/tstwxqtx.html