- Home /
Text mesh (font material) renders on top of everything, any way to change that?
I have these objects with some text on them floating in my space (labeling things as it were). My problem is that apparently, text is drawn last, so it is visible always, even if it should be occluded by intervening solid objects. Is there a way to fix that? Do I have to muck with the shader on it?
Its 2020, For new Text $$anonymous$$esh Pro you can use distance field shader here is the demo https://youtu.be/7HnixlwlQ5Q
Answer by Jessy · Jan 26, 2011 at 01:13 AM
Yes, you have to use a different shader. Here's one to start with:
Wow. I didnt even know the regular one did that. Nice to learn something new.
The link is now broken. Can someone post here the shader? Thank you very much.
Answer by Ngoc Ngo · Aug 22, 2014 at 12:30 AM
The shader has been moved here: http://wiki.unity3d.com/index.php?title=3DText
Shader "GUI/3D Text Shader" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Off ZWrite Off Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Color [_Color]
SetTexture [_MainTex] {
combine primary, texture * primary
}
}
}
}
This one won't use the color set with TextMesh though.
Worked perfectly for me. As you said, the shader "disables" the color of Text$$anonymous$$esh, but you can set the color with the Shader ins$$anonymous$$d of the Text$$anonymous$$esh, so it's pretty much the same result. I attached a pic for future readers.
Answer by tinytiger2424 · Jul 05, 2016 at 06:11 AM
I just got this working in my most recent project. That link someone else posted has instructions how to use it and you can set the colour too! (Link: http://wiki.unity3d.com/index.php?title=3DText)
Code
Shader "GUI/3D Text Shader" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Off ZWrite Off Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Color [_Color]
SetTexture [_MainTex] {
combine primary, texture * primary
}
}
}
}
Answer by Gan_HOPE326 · Jul 19, 2016 at 04:03 PM
This is very old and may not be relevant any more, but in case someone still has this issue I just found out a super-easy solution to this problem: just set everything else's material's Rendering Mode to "transparent". In that way the right order of drawing is preserved.
Wouldn't that remove all those materials' support for deferred rendering though?
Uhm, this is a very bad idea. Rendering trasparent things is much more performance intensive, among other things that it will mess up
Answer by Cascho01 · Nov 23, 2015 at 11:52 AM
@Ngoc Ngo Any way to get the color set with TextMesh working?
I don't know, but I haven't checked in a year, so maybe somebody has done it somewhere. $$anonymous$$eep looking. Good luck! And don't forget to post it here once you found a way, it may help someone.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101116im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2.5D perspective rendering order challenges 2 Answers
Using Color.Lerp with Lightweight Render Pipeline 1 Answer
Layer Dependent Reflections 1 Answer
Strange rendering - unsupported shader? -> Pink screen 0 Answers
How to remove URP from the project 0 Answers