Unlit - Dynamic Font (AlphaClip).shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Unlit/Dynamic Font (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 = tex2D(_MainTex, IN.texcoord) * IN.color;
  58. half4 col = IN.color;
  59. col.a *= tex2D(_MainTex, IN.texcoord).a;
  60. float2 factor = abs(IN.worldPos);
  61. float val = 1.0 - max(factor.x, factor.y);
  62. // Option 1: 'if' statement
  63. if (val < 0.0) col.a = 0.0;
  64. // Option 2: no 'if' statement -- may be faster on some devices
  65. //col.a *= ceil(clamp(val, 0.0, 1.0));
  66. return col;
  67. }
  68. ENDCG
  69. }
  70. }
  71. SubShader
  72. {
  73. LOD 100
  74. Tags
  75. {
  76. "Queue" = "Transparent"
  77. "IgnoreProjector" = "True"
  78. "RenderType" = "Transparent"
  79. }
  80. Pass
  81. {
  82. Cull Off
  83. Lighting Off
  84. ZWrite Off
  85. Fog { Mode Off }
  86. ColorMask RGB
  87. AlphaTest Greater .01
  88. Blend SrcAlpha OneMinusSrcAlpha
  89. ColorMaterial AmbientAndDiffuse
  90. SetTexture [_MainTex]
  91. {
  92. Combine Texture * Primary
  93. }
  94. }
  95. }
  96. }