TMP_Bitmap-Custom-Atlas.shader (3464B)
1 Shader "TextMeshPro/Bitmap Custom Atlas" { 2 3 Properties { 4 _MainTex ("Font Atlas", 2D) = "white" {} 5 _FaceTex ("Font Texture", 2D) = "white" {} 6 _FaceColor ("Text Color", Color) = (1,1,1,1) 7 8 _VertexOffsetX ("Vertex OffsetX", float) = 0 9 _VertexOffsetY ("Vertex OffsetY", float) = 0 10 _MaskSoftnessX ("Mask SoftnessX", float) = 0 11 _MaskSoftnessY ("Mask SoftnessY", float) = 0 12 13 _ClipRect("Clip Rect", vector) = (-32767, -32767, 32767, 32767) 14 _Padding ("Padding", float) = 0 15 16 _StencilComp("Stencil Comparison", Float) = 8 17 _Stencil("Stencil ID", Float) = 0 18 _StencilOp("Stencil Operation", Float) = 0 19 _StencilWriteMask("Stencil Write Mask", Float) = 255 20 _StencilReadMask("Stencil Read Mask", Float) = 255 21 22 _ColorMask("Color Mask", Float) = 15 23 } 24 25 SubShader{ 26 27 Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } 28 29 Stencil 30 { 31 Ref[_Stencil] 32 Comp[_StencilComp] 33 Pass[_StencilOp] 34 ReadMask[_StencilReadMask] 35 WriteMask[_StencilWriteMask] 36 } 37 38 39 Lighting Off 40 Cull [_CullMode] 41 ZTest [unity_GUIZTestMode] 42 ZWrite Off 43 Fog { Mode Off } 44 Blend SrcAlpha OneMinusSrcAlpha 45 ColorMask[_ColorMask] 46 47 Pass { 48 CGPROGRAM 49 #pragma vertex vert 50 #pragma fragment frag 51 52 #pragma multi_compile __ UNITY_UI_CLIP_RECT 53 #pragma multi_compile __ UNITY_UI_ALPHACLIP 54 55 56 #include "UnityCG.cginc" 57 58 struct appdata_t { 59 float4 vertex : POSITION; 60 fixed4 color : COLOR; 61 float2 texcoord0 : TEXCOORD0; 62 float2 texcoord1 : TEXCOORD1; 63 }; 64 65 struct v2f { 66 float4 vertex : SV_POSITION; 67 fixed4 color : COLOR; 68 float2 texcoord0 : TEXCOORD0; 69 float2 texcoord1 : TEXCOORD1; 70 float4 mask : TEXCOORD2; 71 }; 72 73 uniform sampler2D _MainTex; 74 uniform sampler2D _FaceTex; 75 uniform float4 _FaceTex_ST; 76 uniform fixed4 _FaceColor; 77 78 uniform float _VertexOffsetX; 79 uniform float _VertexOffsetY; 80 uniform float4 _ClipRect; 81 uniform float _MaskSoftnessX; 82 uniform float _MaskSoftnessY; 83 84 float2 UnpackUV(float uv) 85 { 86 float2 output; 87 output.x = floor(uv / 4096); 88 output.y = uv - 4096 * output.x; 89 90 return output * 0.001953125; 91 } 92 93 v2f vert (appdata_t v) 94 { 95 float4 vert = v.vertex; 96 vert.x += _VertexOffsetX; 97 vert.y += _VertexOffsetY; 98 99 vert.xy += (vert.w * 0.5) / _ScreenParams.xy; 100 101 float4 vPosition = UnityPixelSnap(UnityObjectToClipPos(vert)); 102 103 fixed4 faceColor = v.color; 104 faceColor *= _FaceColor; 105 106 v2f OUT; 107 OUT.vertex = vPosition; 108 OUT.color = faceColor; 109 OUT.texcoord0 = v.texcoord0; 110 OUT.texcoord1 = TRANSFORM_TEX(UnpackUV(v.texcoord1), _FaceTex); 111 float2 pixelSize = vPosition.w; 112 pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1])); 113 114 // Clamp _ClipRect to 16bit. 115 float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); 116 OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy)); 117 118 return OUT; 119 } 120 121 fixed4 frag (v2f IN) : SV_Target 122 { 123 fixed4 color = tex2D(_MainTex, IN.texcoord0) * tex2D(_FaceTex, IN.texcoord1) * IN.color; 124 125 // Alternative implementation to UnityGet2DClipping with support for softness. 126 #if UNITY_UI_CLIP_RECT 127 half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw); 128 color *= m.x * m.y; 129 #endif 130 131 #if UNITY_UI_ALPHACLIP 132 clip(color.a - 0.001); 133 #endif 134 135 return color; 136 } 137 ENDCG 138 } 139 } 140 141 CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI" 142 }