只有阴影pass,请自行合并,需要指定高度,忽略深度检测,需要控制好排序,或者去掉忽略,视情况而定,最后我觉得还是shadowmap好
Shader "Custom/MeshShadow" { Properties { _ShadowOffset("ShadowOffset",vector) = (0,0,0,0) _ShadowHeight("ShadowHeight",float) = 0 } SubShader { Tags { "RenderType"="Opaque" "Queue"="Transparent"} Pass { Name "MeshShadow" Tags {"LightMode" = "Always"} Blend One OneMinusSrcAlpha ZWrite Off ZTest Always Stencil { Ref 2 Comp NotEqual Pass Replace } CGPROGRAM #include "UnityCG.cginc" #pragma vertex vert #pragma fragment frag float4 _ShadowOffset; float _ShadowHeight; struct v2f { float4 pos : POSITION; float4 texcoord : TEXCOORD0; }; v2f vert ( appdata_base v ) { v2f o; float4x4 _RotMatrix = _Object2World; _RotMatrix[0][3] = 0; _RotMatrix[1][3] = 0; _RotMatrix[2][3] = 0; float3 tempPos = float3(_Object2World[0][3],_Object2World[1][3],_Object2World[2][3]); float4 vertexPos = mul(_RotMatrix,v.vertex); vertexPos.x += _ShadowOffset.x * vertexPos.y + _ShadowOffset.x; vertexPos.z += _ShadowOffset.y * vertexPos.y + _ShadowOffset.y; vertexPos.xyz += tempPos; vertexPos.y = _ShadowHeight; o.pos = mul(UNITY_MATRIX_VP, vertexPos); o.texcoord = v.texcoord; return o; } fixed4 frag(v2f i) :COLOR { return fixed4(0,0,0,0.3); } ENDCG } } }
时间: 2024-10-13 15:10:41