添加阴影
在 Unity 中我们通常给物体添加阴影来增加真实感。
但是我们直接这么做的话会在画面中也看到一个白色的平面。所以我们需要一个透明的平面,但能够接收阴影。为了达到这个目的,我们需要一个自定义的着色器。
Shader "FX/Matte Shadow" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
Blend Zero SrcColor
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo*atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = _Color;
o.Albedo