| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- Shader "Custom/DirectionalWipeWithRange"
- {
- Properties
- {
- _MainTex("Main Texture", 2D) = "white" {}
- _Color("Color Tint", Color) = (1,1,1,1)
- _Cutoff("Cutoff (0=全显, 1=全隐)", Range(0,1)) = 0
- _EdgeSmooth("Edge Smoothness", Range(0.001, 0.3)) = 0.05
- _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" = "Geometry" "RenderType" = "Opaque" }
- LOD 200
- ZWrite On
- Blend SrcAlpha OneMinusSrcAlpha
- Cull Off
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- float4 _Color;
- float _Cutoff;
- float _EdgeSmooth;
- 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;
- float alphaMask = smoothstep(revCutoff - _EdgeSmooth, revCutoff + _EdgeSmooth, wipeCoord);
- clip(alphaMask - 0.01);
- fixed4 col = tex2D(_MainTex, i.uv) * _Color;
- col.a *= alphaMask;
- return col;
- }
- ENDCG
- }
- }
- }
|