unity3d - How to use UGUI mask and custom font correctly -


i want use mask component show apart of text custom font.

but pictures say:

when use custom font "none (material)", mask works well, text abnormal. (picture 1)

someone taught me change text's material "sprites-default", text show correctly. , when change material, text show normal indeed, mask doesn't work, can't cover text out of mask. (picture 2)

how should make of them work well?

picture 1

picture 2

when use sprites-default material, unity warned me "material sprite/default doesn't have stencil properties". copy stencil properties ui-defaultfont.shader. god works.

here modified shader:

create material shader , use material.enter image description here

shader "custom/spritesdefaultfont" { properties {     [perrendererdata] _maintex ("sprite texture", 2d) = "white" {}     _color ("tint", color) = (1,1,1,1)     [materialtoggle] pixelsnap ("pixel snap", float) = 0      _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 }  subshader {     tags     {          "queue"="transparent"          "ignoreprojector"="true"          "rendertype"="transparent"          "previewtype"="plane"         "canusespriteatlas"="true"     }      stencil     {         ref [_stencil]         comp [_stencilcomp]         pass [_stencilop]          readmask [_stencilreadmask]         writemask [_stencilwritemask]     }      cull off     lighting off     zwrite off     blend 1 oneminussrcalpha      pass     {     cgprogram         #pragma vertex vert         #pragma fragment frag         #pragma multi_compile _ pixelsnap_on         #include "unitycg.cginc"          struct appdata_t         {             float4 vertex   : position;             float4 color    : color;             float2 texcoord : texcoord0;         };          struct v2f         {             float4 vertex   : sv_position;             fixed4 color    : color;             half2 texcoord  : texcoord0;         };          fixed4 _color;          v2f vert(appdata_t in)         {             v2f out;             out.vertex = mul(unity_matrix_mvp, in.vertex);             out.texcoord = in.texcoord;             out.color = in.color * _color;             #ifdef pixelsnap_on             out.vertex = unitypixelsnap (out.vertex);             #endif              return out;         }          sampler2d _maintex;          fixed4 frag(v2f in) : sv_target         {             fixed4 c = tex2d(_maintex, in.texcoord) * in.color;             c.rgb *= c.a;             return c;         }     endcg     } } } 

Comments