DirectionalWipeWithRange.shader 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Shader "Custom/DirectionalWipeWithRange"
  2. {
  3. Properties
  4. {
  5. _MainTex("Main Texture", 2D) = "white" {}
  6. _Color("Color Tint", Color) = (1,1,1,1)
  7. _Cutoff("Cutoff (0=全显, 1=全隐)", Range(0,1)) = 0
  8. _EdgeSmooth("Edge Smoothness", Range(0.001, 0.3)) = 0.05
  9. _Axis("Axis (0=X,1=Y,2=Z)", Range(0,2)) = 1
  10. _Direction("Direction (1=正向,-1=反向)", Float) = 1
  11. _WipeMin("Wipe Range Min", Float) = -1
  12. _WipeMax("Wipe Range Max", Float) = 1
  13. }
  14. SubShader
  15. {
  16. Tags { "Queue" = "Geometry" "RenderType" = "Opaque" }
  17. LOD 200
  18. ZWrite On
  19. Blend SrcAlpha OneMinusSrcAlpha
  20. Cull Off
  21. Pass
  22. {
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #include "UnityCG.cginc"
  27. sampler2D _MainTex;
  28. float4 _Color;
  29. float _Cutoff;
  30. float _EdgeSmooth;
  31. float _Axis;
  32. float _Direction;
  33. float _WipeMin;
  34. float _WipeMax;
  35. struct appdata
  36. {
  37. float4 vertex : POSITION;
  38. float2 uv : TEXCOORD0;
  39. };
  40. struct v2f
  41. {
  42. float2 uv : TEXCOORD0;
  43. float4 vertex : SV_POSITION;
  44. float3 localPos : TEXCOORD1;
  45. };
  46. v2f vert(appdata v)
  47. {
  48. v2f o;
  49. o.vertex = UnityObjectToClipPos(v.vertex);
  50. o.uv = v.uv;
  51. o.localPos = v.vertex.xyz;
  52. return o;
  53. }
  54. fixed4 frag(v2f i) : SV_Target
  55. {
  56. float3 dir = (_Axis < 0.5) ? float3(1,0,0) : (_Axis < 1.5 ? float3(0,1,0) : float3(0,0,1));
  57. dir *= _Direction;
  58. float proj = dot(i.localPos, dir);
  59. float wipeCoord = (proj - _WipeMin) / (_WipeMax - _WipeMin);
  60. float revCutoff = 1.0 - _Cutoff;
  61. float alphaMask = smoothstep(revCutoff - _EdgeSmooth, revCutoff + _EdgeSmooth, wipeCoord);
  62. clip(alphaMask - 0.01);
  63. fixed4 col = tex2D(_MainTex, i.uv) * _Color;
  64. col.a *= alphaMask;
  65. return col;
  66. }
  67. ENDCG
  68. }
  69. }
  70. }