TMP_Bitmap-Mobile.shader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. _CullMode ("Cull Mode", Float) = 0
  17. _ColorMask ("Color Mask", Float) = 15
  18. }
  19. SubShader {
  20. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  21. Stencil
  22. {
  23. Ref[_Stencil]
  24. Comp[_StencilComp]
  25. Pass[_StencilOp]
  26. ReadMask[_StencilReadMask]
  27. WriteMask[_StencilWriteMask]
  28. }
  29. Lighting Off
  30. Cull [_CullMode]
  31. ZTest [unity_GUIZTestMode]
  32. ZWrite Off
  33. Fog { Mode Off }
  34. Blend SrcAlpha OneMinusSrcAlpha
  35. ColorMask[_ColorMask]
  36. Pass {
  37. CGPROGRAM
  38. #pragma vertex vert
  39. #pragma fragment frag
  40. #pragma fragmentoption ARB_precision_hint_fastest
  41. #pragma multi_compile __ UNITY_UI_CLIP_RECT
  42. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  43. #include "UnityCG.cginc"
  44. #include "UnityUI.cginc"
  45. struct appdata_t
  46. {
  47. float4 vertex : POSITION;
  48. fixed4 color : COLOR;
  49. float2 texcoord0 : TEXCOORD0;
  50. float2 texcoord1 : TEXCOORD1;
  51. };
  52. struct v2f
  53. {
  54. float4 vertex : POSITION;
  55. fixed4 color : COLOR;
  56. float2 texcoord0 : TEXCOORD0;
  57. float4 mask : TEXCOORD2;
  58. };
  59. sampler2D _MainTex;
  60. fixed4 _Color;
  61. float _DiffusePower;
  62. uniform float _VertexOffsetX;
  63. uniform float _VertexOffsetY;
  64. uniform float4 _ClipRect;
  65. uniform float _MaskSoftnessX;
  66. uniform float _MaskSoftnessY;
  67. uniform float _UIMaskSoftnessX;
  68. uniform float _UIMaskSoftnessY;
  69. uniform int _UIVertexColorAlwaysGammaSpace;
  70. v2f vert (appdata_t v)
  71. {
  72. v2f OUT;
  73. float4 vert = v.vertex;
  74. vert.x += _VertexOffsetX;
  75. vert.y += _VertexOffsetY;
  76. vert.xy += (vert.w * 0.5) / _ScreenParams.xy;
  77. if (_UIVertexColorAlwaysGammaSpace && !IsGammaSpace())
  78. {
  79. v.color.rgb = UIGammaToLinear(v.color.rgb);
  80. }
  81. OUT.vertex = UnityPixelSnap(UnityObjectToClipPos(vert));
  82. OUT.color = v.color;
  83. OUT.color *= _Color;
  84. OUT.color.rgb *= _DiffusePower;
  85. OUT.texcoord0 = v.texcoord0;
  86. float2 pixelSize = OUT.vertex.w;
  87. //pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1]));
  88. // Clamp _ClipRect to 16bit.
  89. const float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
  90. const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
  91. OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
  92. return OUT;
  93. }
  94. fixed4 frag (v2f IN) : COLOR
  95. {
  96. fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0).a);
  97. // Alternative implementation to UnityGet2DClipping with support for softness.
  98. #if UNITY_UI_CLIP_RECT
  99. half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
  100. color *= m.x * m.y;
  101. #endif
  102. #if UNITY_UI_ALPHACLIP
  103. clip(color.a - 0.001);
  104. #endif
  105. return color;
  106. }
  107. ENDCG
  108. }
  109. }
  110. SubShader {
  111. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  112. Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
  113. Blend SrcAlpha OneMinusSrcAlpha
  114. BindChannels {
  115. Bind "Color", color
  116. Bind "Vertex", vertex
  117. Bind "TexCoord", texcoord0
  118. }
  119. Pass {
  120. SetTexture [_MainTex] {
  121. constantColor [_Color] combine constant * primary, constant * texture
  122. }
  123. }
  124. }
  125. CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI"
  126. }