| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- Shader "Custom/DirectionalWipeTransparent"
- {
- Properties
- {
- _MainTex("Texture", 2D) = "white" {}
- _Color("Color Tint", Color) = (1,1,1,1)
- _Threshold("Wipe Threshold", Range(-1, 1)) = -1
- _EdgeSmooth("Edge Smoothness", Range(0.001, 1)) = 0.1
- _WipeDir("Wipe Direction Vector", Vector) = (1, 0, 0, 0) // 默认沿X轴
- }
- SubShader
- {
- Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
- LOD 200
- Blend SrcAlpha OneMinusSrcAlpha
- ZWrite Off
- Cull Off
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- float4 _Color;
- float _Threshold;
- float _EdgeSmooth;
- float4 _WipeDir; // 方向向量,xyz有效
- 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
- {
- // 方向向量点乘位置向量,得到在该方向上的投影值
- float wipeCoord = dot(i.localPos, _WipeDir.xyz);
- // 使用 smoothstep 实现边缘渐变
- float alphaMask = smoothstep(_Threshold - _EdgeSmooth, _Threshold + _EdgeSmooth, wipeCoord);
- fixed4 col = tex2D(_MainTex, i.uv) * _Color;
- col.a *= alphaMask;
- return col;
- }
- ENDCG
- }
- }
- }
|