DirectionalWipeHardCut.shader 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Shader "Custom/DirectionalWipeHardCut"
  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. _Axis("Axis (0=X,1=Y,2=Z)", Range(0,2)) = 1
  9. _Direction("Direction (1=正向,-1=反向)", Float) = 1
  10. _WipeMin("Wipe Range Min", Float) = -1
  11. _WipeMax("Wipe Range Max", Float) = 1
  12. }
  13. SubShader
  14. {
  15. Tags { "Queue" = "AlphaTest" "RenderType" = "TransparentCutout" }
  16. LOD 200
  17. ZWrite On
  18. Cull Off // 关键点:关闭剔除,支持双面
  19. AlphaToMask On
  20. Blend 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 _Axis;
  31. float _Direction;
  32. float _WipeMin;
  33. float _WipeMax;
  34. struct appdata
  35. {
  36. float4 vertex : POSITION;
  37. float2 uv : TEXCOORD0;
  38. };
  39. struct v2f
  40. {
  41. float2 uv : TEXCOORD0;
  42. float4 vertex : SV_POSITION;
  43. float3 localPos : TEXCOORD1;
  44. };
  45. v2f vert(appdata v)
  46. {
  47. v2f o;
  48. o.vertex = UnityObjectToClipPos(v.vertex);
  49. o.uv = v.uv;
  50. o.localPos = v.vertex.xyz;
  51. return o;
  52. }
  53. fixed4 frag(v2f i) : SV_Target
  54. {
  55. float3 dir = (_Axis < 0.5) ? float3(1,0,0) : (_Axis < 1.5 ? float3(0,1,0) : float3(0,0,1));
  56. dir *= _Direction;
  57. float proj = dot(i.localPos, dir);
  58. float wipeCoord = (proj - _WipeMin) / (_WipeMax - _WipeMin);
  59. float revCutoff = 1.0 - _Cutoff;
  60. clip(wipeCoord - revCutoff); // 直接硬切
  61. fixed4 col = tex2D(_MainTex, i.uv) * _Color;
  62. return col;
  63. }
  64. ENDCG
  65. }
  66. }
  67. }