I want to achieve a shader that has billboard shadow caster"means shadow always face to light include any light which cast shadow"
here is my code
Pass{
Tags {"LightMode" = "ShadowCaster"}
LOD 100
ztest off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
struct appdata
{
float4 vertex:POSITION;
float2 texcoord:TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
float _MaxHeight;
float _XScale;
struct v2f {
float4 vertex:SV_POSITION;
float2 texcoord:TEXCOORD0;
};
v2f vert(appdata v){
v2f o;
float3 forward=mul(unity_WorldToObject,_WorldSpaceLightPos0.xyz).xyz;
forward.y=0;
forward=normalize(forward);
float3 up=float3(0,1,0);
float3 right=normalize(cross(forward,up));
up=normalize(cross(right,forward));
float sc=lerp(0,_XScale,v.vertex.y/_MaxHeight);
float3 vertex= v.vertex.x*right+v.vertex.y*up;
o.vertex=UnityObjectToClipPos(vertex);
o.texcoord=v.texcoord;
return o;
}
float4 frag(v2f i):SV_Target
{
float4 c=tex2D(_MainTex,i.texcoord);
clip(c.a-0.8);
return c;
}
ENDCG
}
in standard render pipeline the effect is correct like this img
both of the directional light and spot light work very well with correct billboard shadow.
but if in urp,the spot light shadow will be wrong like this
as you can see,the spot light shadow also cast by sunlight billboard.
so how can i fix it.thanks