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