Hi to all,
I am experiencing a problem and i would appreciate some help please.
I am using 3d text for displaying some info in my 3d world. The problem i am experiecning is that the 3d text is shown even when it is behind other 3d objects or even my character. Is there a way to make the 3d text appear correctly and not overlapping anything else.
Are there any other alternatives? The positioning of the text is really important and must be within the 3d environment relative to specific objects.
Thanks
TextMeshes by default get a material which uses the “GUI/Text Shader” shader. This shader always gets drawn after everything else for a particular camera, and so appears on top of everything even when the object is covered up.
To fix it, you need to import your own TrueType font file (or make a custom font texture), then create a new material and apply the font’s texture to it. You can then choose another shader for that material. As far as I can see, none of the built-in shaders are exactly the same as GUI/Text Shader minus the draw-in-front-of-everything behaviour, but there’s at least one on the wiki that would work for this purpose. Finally, drop the new material onto your TextMesh objects.
Thanks for your reply,
I have done what you told me and now i have another problem. The text that i get is not readable.It is not some blocks of solid color like the ones that appear when you are not using a shader who is appropriate for text but they are parts of letters that are not shown in full.
Even if i create a 3d text and just switch from the standard arial rounded font to the courier that is located within the standard assets package, i get the exact same problem.
Any ideas?
Hello,
I’d be interested in a solution as well. Tried as suggested, but the text still gets drawn in front of every object. I’m not experienced enough with shaders, to know where to start. Maybe someone can suggest.
Thanks in advance!
Take the “ztest always” line out.
–Eric
Thanks! That did the trick.
Now, I’m wondering how to change the text color. Even though, the shader color is set to “white”, the text is solid black.
Here is the shader:
Shader "GUI/Textured Text Shader"
{
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Lighting Off
cull off
Zwrite off
Fog { Mode Off }
Tags {"Queue" = "Transparent" }
Pass {
Blend SrcAlpha OneMinusSrcAlpha
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * constant, texture * constant
}
}
}
}
Any idea, why this happens?
That shader is for colored fonts. If you want to use a regular font then use the regular font shader (modified with the removal of the ztest line of course).
–Eric
Yes, that was my first idea too, but the regular font shader does not allow editing. Well, at least the “Edit Shader” option is grey and can not be selected. :?
Download the shader source and edit that.
–Eric
Thanks! I’ll give it a try