TMP_Bitmap-Mobile.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Shader "TextMeshPro/Mobile/Bitmap" {
  2. Properties {
  3. _MainTex ("Font Atlas", 2D) = "white" {}
  4. _Color ("Text Color", Color) = (1,1,1,1)
  5. _DiffusePower ("Diffuse Power", Range(1.0,4.0)) = 1.0
  6. _VertexOffsetX("Vertex OffsetX", float) = 0
  7. _VertexOffsetY("Vertex OffsetY", float) = 0
  8. _MaskSoftnessX("Mask SoftnessX", float) = 0
  9. _MaskSoftnessY("Mask SoftnessY", float) = 0
  10. _ClipRect("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
  11. _StencilComp("Stencil Comparison", Float) = 8
  12. _Stencil("Stencil ID", Float) = 0
  13. _StencilOp("Stencil Operation", Float) = 0
  14. _StencilWriteMask("Stencil Write Mask", Float) = 255
  15. _StencilReadMask("Stencil Read Mask", Float) = 255
  16. _ColorMask("Color Mask", Float) = 15
  17. }
  18. SubShader {
  19. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  20. Stencil
  21. {
  22. Ref[_Stencil]
  23. Comp[_StencilComp]
  24. Pass[_StencilOp]
  25. ReadMask[_StencilReadMask]
  26. WriteMask[_StencilWriteMask]
  27. }
  28. Lighting Off
  29. Cull Off
  30. ZTest [unity_GUIZTestMode]
  31. ZWrite Off
  32. Fog { Mode Off }
  33. Blend SrcAlpha OneMinusSrcAlpha
  34. ColorMask[_ColorMask]
  35. Pass {
  36. CGPROGRAM
  37. #pragma vertex vert
  38. #pragma fragment frag
  39. #pragma fragmentoption ARB_precision_hint_fastest
  40. #pragma multi_compile __ UNITY_UI_CLIP_RECT
  41. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  42. #include "UnityCG.cginc"
  43. struct appdata_t {
  44. float4 vertex : POSITION;
  45. fixed4 color : COLOR;
  46. float2 texcoord0 : TEXCOORD0;
  47. float2 texcoord1 : TEXCOORD1;
  48. };
  49. struct v2f {
  50. float4 vertex : POSITION;
  51. fixed4 color : COLOR;
  52. float2 texcoord0 : TEXCOORD0;
  53. float4 mask : TEXCOORD2;
  54. };
  55. sampler2D _MainTex;
  56. fixed4 _Color;
  57. float _DiffusePower;
  58. uniform float _VertexOffsetX;
  59. uniform float _VertexOffsetY;
  60. uniform float4 _ClipRect;
  61. uniform float _MaskSoftnessX;
  62. uniform float _MaskSoftnessY;
  63. v2f vert (appdata_t v)
  64. {
  65. v2f OUT;
  66. float4 vert = v.vertex;
  67. vert.x += _VertexOffsetX;
  68. vert.y += _VertexOffsetY;
  69. vert.xy += (vert.w * 0.5) / _ScreenParams.xy;
  70. OUT.vertex = UnityPixelSnap(UnityObjectToClipPos(vert));
  71. OUT.color = v.color;
  72. OUT.color *= _Color;
  73. OUT.color.rgb *= _DiffusePower;
  74. OUT.texcoord0 = v.texcoord0;
  75. float2 pixelSize = OUT.vertex.w;
  76. //pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1]));
  77. // Clamp _ClipRect to 16bit.
  78. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
  79. OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
  80. return OUT;
  81. }
  82. fixed4 frag (v2f IN) : COLOR
  83. {
  84. fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0).a);
  85. // Alternative implementation to UnityGet2DClipping with support for softness.
  86. #if UNITY_UI_CLIP_RECT
  87. half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
  88. color *= m.x * m.y;
  89. #endif
  90. #if UNITY_UI_ALPHACLIP
  91. clip(color.a - 0.001);
  92. #endif
  93. return color;
  94. }
  95. ENDCG
  96. }
  97. }
  98. SubShader {
  99. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  100. Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
  101. Blend SrcAlpha OneMinusSrcAlpha
  102. BindChannels {
  103. Bind "Color", color
  104. Bind "Vertex", vertex
  105. Bind "TexCoord", texcoord0
  106. }
  107. Pass {
  108. SetTexture [_MainTex] {
  109. constantColor [_Color] combine constant * primary, constant * texture
  110. }
  111. }
  112. }
  113. CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI"
  114. }