Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.5 KiB

  1. Shader "TextMeshPro/Mobile/Bitmap" {
  2. Properties {
  3. _MainTex ("Font Atlas", 2D) = "white" {}
  4. [HDR]_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. struct appdata_t {
  45. float4 vertex : POSITION;
  46. fixed4 color : COLOR;
  47. float2 texcoord0 : TEXCOORD0;
  48. float2 texcoord1 : TEXCOORD1;
  49. };
  50. struct v2f {
  51. float4 vertex : POSITION;
  52. fixed4 color : COLOR;
  53. float2 texcoord0 : TEXCOORD0;
  54. float4 mask : TEXCOORD2;
  55. };
  56. sampler2D _MainTex;
  57. fixed4 _Color;
  58. float _DiffusePower;
  59. uniform float _VertexOffsetX;
  60. uniform float _VertexOffsetY;
  61. uniform float4 _ClipRect;
  62. uniform float _MaskSoftnessX;
  63. uniform float _MaskSoftnessY;
  64. v2f vert (appdata_t v)
  65. {
  66. v2f OUT;
  67. float4 vert = v.vertex;
  68. vert.x += _VertexOffsetX;
  69. vert.y += _VertexOffsetY;
  70. vert.xy += (vert.w * 0.5) / _ScreenParams.xy;
  71. OUT.vertex = UnityPixelSnap(UnityObjectToClipPos(vert));
  72. OUT.color = v.color;
  73. OUT.color *= _Color;
  74. OUT.color.rgb *= _DiffusePower;
  75. OUT.texcoord0 = v.texcoord0;
  76. float2 pixelSize = OUT.vertex.w;
  77. //pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1]));
  78. // Clamp _ClipRect to 16bit.
  79. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
  80. OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
  81. return OUT;
  82. }
  83. fixed4 frag (v2f IN) : COLOR
  84. {
  85. fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0).a);
  86. // Alternative implementation to UnityGet2DClipping with support for softness.
  87. #if UNITY_UI_CLIP_RECT
  88. half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
  89. color *= m.x * m.y;
  90. #endif
  91. #if UNITY_UI_ALPHACLIP
  92. clip(color.a - 0.001);
  93. #endif
  94. return color;
  95. }
  96. ENDCG
  97. }
  98. }
  99. SubShader {
  100. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  101. Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
  102. Blend SrcAlpha OneMinusSrcAlpha
  103. BindChannels {
  104. Bind "Color", color
  105. Bind "Vertex", vertex
  106. Bind "TexCoord", texcoord0
  107. }
  108. Pass {
  109. SetTexture [_MainTex] {
  110. constantColor [_Color] combine constant * primary, constant * texture
  111. }
  112. }
  113. }
  114. CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI"
  115. }