TMP_Bitmap-Mobile.shader (3508B)
1 Shader "TextMeshPro/Mobile/Bitmap" { 2 3 Properties { 4 _MainTex ("Font Atlas", 2D) = "white" {} 5 _Color ("Text Color", Color) = (1,1,1,1) 6 _DiffusePower ("Diffuse Power", Range(1.0,4.0)) = 1.0 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 15 _StencilComp("Stencil Comparison", Float) = 8 16 _Stencil("Stencil ID", Float) = 0 17 _StencilOp("Stencil Operation", Float) = 0 18 _StencilWriteMask("Stencil Write Mask", Float) = 255 19 _StencilReadMask("Stencil Read Mask", Float) = 255 20 21 _ColorMask("Color Mask", Float) = 15 22 } 23 24 SubShader { 25 26 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 27 28 Stencil 29 { 30 Ref[_Stencil] 31 Comp[_StencilComp] 32 Pass[_StencilOp] 33 ReadMask[_StencilReadMask] 34 WriteMask[_StencilWriteMask] 35 } 36 37 38 Lighting Off 39 Cull Off 40 ZTest [unity_GUIZTestMode] 41 ZWrite Off 42 Fog { Mode Off } 43 Blend SrcAlpha OneMinusSrcAlpha 44 ColorMask[_ColorMask] 45 46 Pass { 47 CGPROGRAM 48 #pragma vertex vert 49 #pragma fragment frag 50 #pragma fragmentoption ARB_precision_hint_fastest 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 : POSITION; 67 fixed4 color : COLOR; 68 float2 texcoord0 : TEXCOORD0; 69 float4 mask : TEXCOORD2; 70 }; 71 72 sampler2D _MainTex; 73 fixed4 _Color; 74 float _DiffusePower; 75 76 uniform float _VertexOffsetX; 77 uniform float _VertexOffsetY; 78 uniform float4 _ClipRect; 79 uniform float _MaskSoftnessX; 80 uniform float _MaskSoftnessY; 81 82 v2f vert (appdata_t v) 83 { 84 v2f OUT; 85 float4 vert = v.vertex; 86 vert.x += _VertexOffsetX; 87 vert.y += _VertexOffsetY; 88 89 vert.xy += (vert.w * 0.5) / _ScreenParams.xy; 90 91 OUT.vertex = UnityPixelSnap(UnityObjectToClipPos(vert)); 92 OUT.color = v.color; 93 OUT.color *= _Color; 94 OUT.color.rgb *= _DiffusePower; 95 OUT.texcoord0 = v.texcoord0; 96 97 float2 pixelSize = OUT.vertex.w; 98 //pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1])); 99 100 // Clamp _ClipRect to 16bit. 101 float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); 102 OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy)); 103 104 return OUT; 105 } 106 107 fixed4 frag (v2f IN) : COLOR 108 { 109 fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0).a); 110 111 // Alternative implementation to UnityGet2DClipping with support for softness. 112 #if UNITY_UI_CLIP_RECT 113 half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw); 114 color *= m.x * m.y; 115 #endif 116 117 #if UNITY_UI_ALPHACLIP 118 clip(color.a - 0.001); 119 #endif 120 121 return color; 122 } 123 ENDCG 124 } 125 } 126 127 SubShader { 128 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 129 Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off } 130 Blend SrcAlpha OneMinusSrcAlpha 131 BindChannels { 132 Bind "Color", color 133 Bind "Vertex", vertex 134 Bind "TexCoord", texcoord0 135 } 136 Pass { 137 SetTexture [_MainTex] { 138 constantColor [_Color] combine constant * primary, constant * texture 139 } 140 } 141 } 142 143 CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI" 144 }