Skip to content

Commit 9a2f124

Browse files
Add text multisampling option. (#201)
1 parent 1668916 commit 9a2f124

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

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.6.2",
3+
"version": "0.6.5",
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/ShaderGUIs/TextMeshProShaderGUI.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public class TextMeshProShaderGUI : TMP_SDFShaderGUI
1616
{
1717
private static bool doMode = true;
1818

19+
private static readonly ShaderFeature s_MultiSampleFeature = new()
20+
{
21+
label = new GUIContent("Multisample"),
22+
undoLabel = "Multisample",
23+
keywords = new[] { "MULTISAMPLE_ON" },
24+
keywordLabels = new[] { new GUIContent("Off"), new GUIContent("On") }
25+
};
26+
1927
/// <inheritdoc/>
2028
protected override void DoGUI()
2129
{
@@ -27,6 +35,11 @@ protected override void DoGUI()
2735
EndPanel();
2836

2937
base.DoGUI();
38+
39+
// Do Popup was behaving oddly, default to doing it more manually
40+
s_MultiSampleFeature.ReadState(m_Material);
41+
bool newValue = EditorGUILayout.Toggle("Multisample", s_MultiSampleFeature.Active);
42+
s_MultiSampleFeature.SetActive(newValue, m_Material);
3043
}
3144

3245
/// <inheritdoc/>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ SubShader {
106106
#pragma fragment PixShader
107107
#pragma shader_feature_local __ OUTLINE_ON
108108
#pragma shader_feature_local __ UNDERLAY_ON UNDERLAY_INNER
109+
#pragma shader_feature_local __ MULTISAMPLE_ON
109110

110111
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
111112
#pragma multi_compile_local _ _UI_CLIP_RECT_ROUNDED _UI_CLIP_RECT_ROUNDED_INDEPENDENT
@@ -323,13 +324,30 @@ CBUFFER_END
323324
return output;
324325
}
325326

327+
float4 Tex2DMultisample(sampler2D tex, float2 uv)
328+
{
329+
float2 dx = ddx(uv) * 0.25;
330+
float2 dy = ddy(uv) * 0.25;
331+
332+
float4 sample0 = tex2D(tex, uv + dx + dy);
333+
float4 sample1 = tex2D(tex, uv + dx - dy);
334+
float4 sample2 = tex2D(tex, uv - dx + dy);
335+
float4 sample3 = tex2D(tex, uv - dx - dy);
336+
337+
return (sample0 + sample1 + sample2 + sample3) * 0.25;
338+
}
326339

327340
// PIXEL SHADER
328341
fixed4 PixShader(pixel_t input) : SV_Target
329342
{
330343
UNITY_SETUP_INSTANCE_ID(input);
331344

345+
#if MULTISAMPLE_ON
346+
half d = Tex2DMultisample(_MainTex, input.texcoord0.xy).a * input.param.x;
347+
#else
332348
half d = tex2D(_MainTex, input.texcoord0.xy).a * input.param.x;
349+
#endif
350+
333351
half4 c = input.faceColor * saturate(d - input.param.w);
334352

335353
#ifdef OUTLINE_ON

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.6.3",
3+
"version": "0.6.5",
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)