Unity shader 自带阴影

一定要加这一行 #pragma multi_compile_fwdbase
file:///D:/Program%20Files/Unity2018.3/Editor/Data/Documentation/en/Manual/SL-MultipleProgramVariants.html

默认阴影就是 fwdbase + “三剑客”
Unity shader 自带阴影_第1张图片

Shader "Unlit/PCSS"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        // LOD 100

        Pass
        {
            // Pass for ambient light & first pixel light (directional light)
			Tags { "LightMode"="ForwardBase" }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // shadow on 不加默认是关闭的
            #pragma multi_compile_fwdbase

            #include "UnityCG.cginc"
            #include "AutoLight.cginc"

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
                SHADOW_COORDS(1)
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);

                TRANSFER_SHADOW(o);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);

                fixed shadow = SHADOW_ATTENUATION(i);
                col = fixed4(1,1,1,1) * shadow;

                return col;
            }
            ENDCG
        }
    }

    Fallback "Specular"
}

你可能感兴趣的:(unity3d)