I wanted to make a TextMesh to look a little bit more interesting. So I though about using a mask for each character. The obvious way for me was this shader
Shader "GUI/Masked Text Shader" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_MaskTex ("Mask Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Color [_Color]
SetTexture [_MainTex] {
combine primary, texture * primary
}
SetTexture [_MaskTex] {
combine previous * texture
}
}
}
Fallback "Font"
}
So the material gets this shader, the font texture and the mask texture. The uv’s for the mask are now the ones from the font. With tiling of the mask texture, it becomes a little bit configurable. But I can’t get the result I was actually looking for. I wanted every character to be shaded with the whole mask texture. So it would need different uv’s. But I can’t do anything about it, as the mesh of TextMesh’s can not be modified by script.
I know I could modify the font texture or change the mask texture such that it has the same layout as the font texture. But I wanted to get an efficient workflow, which excludes those two. Maybe someone has an idea.