I wanted to make build of a project using custom shader for TextMeshPro text assets. It renders nicely on PC but It gives me block instead when build for the meta Quest 2. For me it looks like it doesn't read the alpha from the atlas assets, thus giving block instead of cutout. Is there a way to prevent this behaviour, in build option or shader ?
Screenshot from unity scene panel (same result in PCVR build)
Screenshot from quest 2 build (android)
Here is the shader (URP)
Shader "Unlit/InvertFontAtlas"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Cull off
Blend SrcAlpha OneMinusSrcAlpha
AlphaToMask On
Blend OneMinusDstColor Zero
AlphaToMask On
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0 Alpha:Blend
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
fixed4 _Color;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
col.rgb = _Color;
col.a = tex2D(_MainTex, i.uv).a;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
ANSWER:
As mentionned by Kevin the AlphaToMask On does not render on Android setup. the workaround is to use the clip(alpha - 0.1). It works better with TextMeshPro clip with 0.5 value instead of 0.1 which gives a bolder font. So the corrected shader looks like that:
Shader "Unlit/InvertFontAtlas"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Cull off
Blend SrcAlpha OneMinusSrcAlpha
//AlphaToMask On
Blend OneMinusDstColor Zero
//AlphaToMask On
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0 Alpha:Blend
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
fixed4 _Color;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
col.rgb = _Color;
col.a = tex2D(_MainTex, i.uv).a;
// here the clip line
clip(col.a - 0.5);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}