Skip to content

Commit 75ad703

Browse files
Text Mesh Pro 2023 Rendering Fix (#215)
Update "Graphics Tools/Text Mesh Pro" for Unity 2023.
1 parent 3d414c0 commit 75ad703

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

com.microsoft.mrtk.graphicstools.shadergraph.unity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.microsoft.mrtk.graphicstools.shadergraph.unity",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"displayName": "MRTK Graphics Tools Shader Graph",
55
"description": "Graphics tools and components for developing Mixed Reality applications in Unity Shader Graph.",
66
"documentationUrl": "https://aka.ms/mrtk3graphics",

com.microsoft.mrtk.graphicstools.unity/Editor/Microsoft.MixedReality.GraphicsTools.Editor.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"expression": "3.0.6",
2626
"define": "GT_USE_TMP"
2727
},
28+
{
29+
"name": "com.unity.ugui",
30+
"expression": "2.0.0",
31+
"define": "GT_USE_TMP"
32+
},
2833
{
2934
"name": "com.unity.ugui",
3035
"expression": "1.0.0",

com.microsoft.mrtk.graphicstools.unity/Runtime/Microsoft.MixedReality.GraphicsTools.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"expression": "3.0.6",
2626
"define": "GT_USE_TMP"
2727
},
28+
{
29+
"name": "com.unity.ugui",
30+
"expression": "2.0.0",
31+
"define": "GT_USE_TMP"
32+
},
2833
{
2934
"name": "com.unity.ugui",
3035
"expression": "1.0.0",

com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsTextMeshPro.shader

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
Shader "Graphics Tools/Text Mesh Pro" {
1919

2020
Properties {
21-
[HDR] _FaceColor ("Face Color", Color) = (1,1,1,1)
21+
_FaceColor ("Face Color", Color) = (1,1,1,1)
2222
_FaceDilate ("Face Dilate", Range(-1,1)) = 0
2323

24-
[HDR] _OutlineColor ("Outline Color", Color) = (0,0,0,1)
24+
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
2525
_OutlineWidth ("Outline Thickness", Range(0,1)) = 0
2626
_OutlineSoftness ("Outline Softness", Range(0,1)) = 0
2727

28-
[HDR] _UnderlayColor ("Border Color", Color) = (0,0,0,.5)
28+
_UnderlayColor ("Border Color", Color) = (0,0,0,.5)
2929
_UnderlayOffsetX ("Border OffsetX", Range(-1,1)) = 0
3030
_UnderlayOffsetY ("Border OffsetY", Range(-1,1)) = 0
3131
_UnderlayDilate ("Border Dilate", Range(-1,1)) = 0
@@ -217,7 +217,11 @@ CBUFFER_END
217217
float4 vertex : POSITION;
218218
float3 normal : NORMAL;
219219
fixed4 color : COLOR;
220+
#if UNITY_VERSION >= 202300 // Unity 6 (2023)+
221+
float4 texcoord0 : TEXCOORD0;
222+
#else
220223
float2 texcoord0 : TEXCOORD0;
224+
#endif
221225
float2 texcoord1 : TEXCOORD1;
222226
};
223227

@@ -239,6 +243,11 @@ CBUFFER_END
239243
#endif
240244
};
241245

246+
#if UNITY_VERSION >= 202300 // Unity 6 (2023)+
247+
float _UIMaskSoftnessX;
248+
float _UIMaskSoftnessY;
249+
int _UIVertexColorAlwaysGammaSpace;
250+
#endif
242251

243252
pixel_t VertShader(vertex_t input)
244253
{
@@ -249,7 +258,11 @@ CBUFFER_END
249258
UNITY_TRANSFER_INSTANCE_ID(input, output);
250259
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
251260

261+
#if UNITY_VERSION >= 202300 // Unity 6 (2023)+
262+
float bold = step(input.texcoord0.w, 0);
263+
#else
252264
float bold = step(input.texcoord1.y, 0);
265+
#endif
253266

254267
float4 vert = input.vertex;
255268
vert.x += _VertexOffsetX;
@@ -260,7 +273,11 @@ CBUFFER_END
260273
pixelSize /= float2(_ScaleX, _ScaleY) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
261274

262275
float scale = rsqrt(dot(pixelSize, pixelSize));
276+
#if UNITY_VERSION >= 202300 // Unity 6 (2023)+
277+
scale *= abs(input.texcoord0.w) * _GradientScale * (_Sharpness + 1);
278+
#else
263279
scale *= abs(input.texcoord1.y) * _GradientScale * (_Sharpness + 1);
280+
#endif
264281
if(UNITY_MATRIX_P[3][3] == 0) scale = lerp(abs(scale) * (1 - _PerspectiveFilter), scale, abs(dot(UnityObjectToWorldNormal(input.normal.xyz), normalize(WorldSpaceViewDir(vert)))));
265282

266283
float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0;
@@ -272,6 +289,12 @@ CBUFFER_END
272289
float bias = (0.5 - weight) * scale - 0.5;
273290
float outline = _OutlineWidth * _ScaleRatioA * 0.5 * scale;
274291

292+
#if UNITY_VERSION >= 202300 // Unity 6 (2023)+
293+
if (_UIVertexColorAlwaysGammaSpace && !IsGammaSpace())
294+
{
295+
input.color.rgb = UIGammaToLinear(input.color.rgb);
296+
}
297+
#endif
275298
float opacity = input.color.a;
276299
#if (UNDERLAY_ON | UNDERLAY_INNER)
277300
opacity = 1.0;
@@ -312,7 +335,13 @@ CBUFFER_END
312335
output.outlineColor = outlineColor;
313336
output.texcoord0 = float4(input.texcoord0.x, input.texcoord0.y, maskUV.x, maskUV.y);
314337
output.param = half4(scale, bias - outline, bias + outline, bias);
315-
output.mask = vert;//half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
338+
output.mask = vert;
339+
// #if UNITY_VERSION >= 202300 // Unity 6 (2023)+
340+
// const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY));
341+
// output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy));
342+
// #else
343+
// output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
344+
// #endif
316345
#if (UNDERLAY_ON || UNDERLAY_INNER)
317346
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
318347
output.underlayParam = half2(layerScale, layerBias);

com.microsoft.mrtk.graphicstools.unity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.microsoft.mrtk.graphicstools.unity",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"displayName": "MRTK Graphics Tools",
55
"description": "Graphics tools and components for developing Mixed Reality applications in Unity.",
66
"documentationUrl": "https://aka.ms/mrtk3graphics",

0 commit comments

Comments
 (0)