Shader "Custom/TransparentShadowCollector"
{
Properties
{
_ShadowIntensity ("Shadow Intensity", Range (0, 1)) = 0.6
}
SubShader
{
Tags {"Queue"="AlphaTest" }
Pass
{
Tags {"LightMode" = "ForwardBase" }
Cull Back
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
uniform float _ShadowIntensity;
struct v2f
{
float4 pos : SV_POSITION;
LIGHTING_COORDS(0,1)
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag(v2f i) : COLOR
{
float attenuation = LIGHT_ATTENUATION(i); //光照衰减
return fixed4(0,0,0,(1-attenuation)*_ShadowIntensity);
}
ENDCG
}
}
Fallback "VertexLit"
}
- 为顶点/片段着色器增加阴影
include "AutoLight.cginc"
"LightMode" = "ForwardBase"
LIGHTING_COORDS(0,1)
define LIGHTING_COORDS(idx1,idx2) float3 _LightCoord : TEXCOORD##idx1; SHADOW_COORDS(idx)
TRANSFER_VERTEX_TO_FRAGMENT(o);
2.LIGHT_ATTENUATION 光照衰减
在没有物体遮挡的情况下光照衰减为0
网友评论