GUI - Text Shader (AlphaClip).shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "GUI/Text Shader (AlphaClip)"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Alpha (A)", 2D) = "white" {}
  7. }
  8. SubShader
  9. {
  10. LOD 200
  11. Tags
  12. {
  13. "Queue" = "Transparent"
  14. "IgnoreProjector" = "True"
  15. "RenderType" = "Transparent"
  16. }
  17. Pass
  18. {
  19. Cull Off
  20. Lighting Off
  21. ZWrite Off
  22. Offset -1, -1
  23. Fog { Mode Off }
  24. //ColorMask RGB
  25. Blend SrcAlpha OneMinusSrcAlpha
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #include "UnityCG.cginc"
  30. sampler2D _MainTex;
  31. float4 _MainTex_ST;
  32. struct appdata_t
  33. {
  34. float4 vertex : POSITION;
  35. half4 color : COLOR;
  36. float2 texcoord : TEXCOORD0;
  37. };
  38. struct v2f
  39. {
  40. float4 vertex : POSITION;
  41. half4 color : COLOR;
  42. float2 texcoord : TEXCOORD0;
  43. float2 worldPos : TEXCOORD1;
  44. };
  45. v2f vert (appdata_t v)
  46. {
  47. v2f o;
  48. o.vertex = UnityObjectToClipPos(v.vertex);
  49. o.color = v.color;
  50. o.texcoord = v.texcoord;
  51. o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
  52. return o;
  53. }
  54. half4 frag (v2f IN) : COLOR
  55. {
  56. // Sample the texture
  57. half4 col = IN.color;
  58. col.a *= tex2D(_MainTex, IN.texcoord).a;
  59. float2 factor = abs(IN.worldPos);
  60. float val = 1.0 - max(factor.x, factor.y);
  61. // Option 1: 'if' statement
  62. if (val < 0.0) col.a = 0.0;
  63. // Option 2: no 'if' statement -- may be faster on some devices
  64. //col.a *= ceil(clamp(val, 0.0, 1.0));
  65. return col;
  66. }
  67. ENDCG
  68. }
  69. }
  70. SubShader
  71. {
  72. LOD 100
  73. Tags
  74. {
  75. "Queue" = "Transparent"
  76. "IgnoreProjector" = "True"
  77. "RenderType" = "Transparent"
  78. }
  79. Pass
  80. {
  81. Cull Off
  82. Lighting Off
  83. ZWrite Off
  84. Fog { Mode Off }
  85. ColorMask RGB
  86. AlphaTest Greater .01
  87. Blend SrcAlpha OneMinusSrcAlpha
  88. ColorMaterial AmbientAndDiffuse
  89. SetTexture [_MainTex]
  90. {
  91. Combine Texture * Primary
  92. }
  93. }
  94. }
  95. }