There are many ways to implement the shadow on the mobile side, which is realized by shader. The principle is relatively simple,
Flatten the model along the y direction and then extend the ZX in one direction, equivalent to rendering the model more than once, and a DC
But it's quite provincial compared to the expensive real-time shadows.
The shadow is the equivalent of a plane, and even if it is, it can accommodate a slightly undulating terrain.
The code is as follows:
Shader"Game-x/planarshadow"{Properties {_strength ("Strength", Range (0.1,Ten)) =3_maintex ("Base (RGB)", 2D) =" White"{} _projplane ("_projplane", Float) =0_lightdir ("_lightdir", Vector) = (0,0.707,0.707)} subshader {Tags {"Queue"="geometry+1" "Rendertype"="Opaque"} pass {Tags {"Lightmode"="Forwardbase"} Blend one srcalpha zwrite off ZTest off Cgprogram #pragmaVertex vert#pragmaFragment Frag#pragmaMulti_compile _blend_alpha_on _blend_alpha_off#pragmaMulti_compile _blend_additive_on _blend_additive_off#include"Unitycg.cginc"#include"Lighting.cginc" structVsin {float4 vertex:position; #ifDefined (_blend_alpha_on) | | Defined (_blend_additive_on)FLOAT2 texcoord:texcoord0; #endif }; structvsout {float4 wpos:sv_position; #ifDefined (_blend_alpha_on) | | Defined (_blend_additive_on)FLOAT2 texcoord:texcoord0; #endif }; float_strength; float_projplane; FLOAT3 _lightdir; Sampler2d _maintex; FLOAT4 _maintex_st; Vsout Vert (Vsin in) {vsout o; FLOAT4 WP=Mul (Unity_objecttoworld, In.vertex); if(Wp.y <_projplane) wp.y=_projplane; Wp.xz= Wp.xz-((WP.Y-_projplane)/_lightdir.y) *_lightdir.xz; WP.Y=_projplane; O.wpos=Mul (UNITY_MATRIX_VP, WP); #ifDefined (_blend_alpha_on) | | Defined (_blend_additive_on)O.texcoord=Transform_tex (In.texcoord, _maintex); #endif returno; } float4 Frag (Vsout in): COLOR {float4 ambient= Unity_lightmodel_ambient *2; floatK = (AMBIENT.R + ambient.g + ambient.b)/_strength; #ifdef _blend_alpha_onfloatA =tex2d (_maintex, In.texcoord). A; K= Lerp (1, K, a); if(A <=0) Clip (-1); #endif#ifdef _blend_additive_on FLOAT3 t=tex2d (_maintex, In.texcoord). RGB; floatQ = (T.R + t.g + t.b)/3; if(Q <=0) Clip (-1); #endif returnFLOAT4 (0,0,0, K); } ENDCG} }}
Shader--the shadow implementation of the mobile side