Unlit - Dynamic Font (SoftClip).shader 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Unlit/Dynamic Font (SoftClip)"
  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. AlphaTest Greater .01
  26. Blend SrcAlpha OneMinusSrcAlpha
  27. CGPROGRAM
  28. #pragma vertex vert
  29. #pragma fragment frag
  30. #include "UnityCG.cginc"
  31. sampler2D _MainTex;
  32. float4 _MainTex_ST;
  33. float2 _ClipSharpness = float2(20.0, 20.0);
  34. struct appdata_t
  35. {
  36. float4 vertex : POSITION;
  37. half4 color : COLOR;
  38. float2 texcoord : TEXCOORD0;
  39. };
  40. struct v2f
  41. {
  42. float4 vertex : POSITION;
  43. half4 color : COLOR;
  44. float2 texcoord : TEXCOORD0;
  45. float2 worldPos : TEXCOORD1;
  46. };
  47. v2f vert (appdata_t v)
  48. {
  49. v2f o;
  50. o.vertex = UnityObjectToClipPos(v.vertex);
  51. o.color = v.color;
  52. o.texcoord = v.texcoord;
  53. o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
  54. return o;
  55. }
  56. half4 frag (v2f IN) : COLOR
  57. {
  58. // Softness factor
  59. float2 factor = (float2(1.0, 1.0) - abs(IN.worldPos)) * _ClipSharpness;
  60. // Sample the texture
  61. half4 col = IN.color;
  62. col.a *= tex2D(_MainTex, IN.texcoord).a;
  63. col.a *= clamp( min(factor.x, factor.y), 0.0, 1.0);
  64. return col;
  65. }
  66. ENDCG
  67. }
  68. }
  69. SubShader
  70. {
  71. LOD 100
  72. Tags
  73. {
  74. "Queue" = "Transparent"
  75. "IgnoreProjector" = "True"
  76. "RenderType" = "Transparent"
  77. }
  78. Pass
  79. {
  80. Cull Off
  81. Lighting Off
  82. ZWrite Off
  83. Fog { Mode Off }
  84. ColorMask RGB
  85. AlphaTest Greater .01
  86. Blend SrcAlpha OneMinusSrcAlpha
  87. ColorMaterial AmbientAndDiffuse
  88. SetTexture [_MainTex]
  89. {
  90. Combine Texture * Primary
  91. }
  92. }
  93. }
  94. }