Shader "Custom/DirectionalWipeHardCut" { Properties { _MainTex("Main Texture", 2D) = "white" {} _Color("Color Tint", Color) = (1,1,1,1) _Cutoff("Cutoff (0=全隐, 1=全显)", Range(0,1)) = 0 _Axis("Axis (0=X,1=Y,2=Z)", Range(0,2)) = 1 _Direction("Direction (1=正向,-1=反向)", Float) = 1 _WipeMin("Wipe Range Min", Float) = -1 _WipeMax("Wipe Range Max", Float) = 1 } SubShader { Tags { "Queue" = "AlphaTest" "RenderType" = "TransparentCutout" } LOD 200 ZWrite On Cull Off // 关键点:关闭剔除,支持双面 AlphaToMask On Blend Off // 不使用透明混合 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float4 _Color; float _Cutoff; float _Axis; float _Direction; float _WipeMin; float _WipeMax; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; float3 localPos : TEXCOORD1; }; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.localPos = v.vertex.xyz; return o; } fixed4 frag(v2f i) : SV_Target { float3 dir = (_Axis < 0.5) ? float3(1,0,0) : (_Axis < 1.5 ? float3(0,1,0) : float3(0,0,1)); dir *= _Direction; float proj = dot(i.localPos, dir); float wipeCoord = (proj - _WipeMin) / (_WipeMax - _WipeMin); float revCutoff = 1.0 - _Cutoff; clip(wipeCoord - revCutoff); // 直接硬切 fixed4 col = tex2D(_MainTex, i.uv) * _Color; return col; } ENDCG } } }