- Home /
3DText Outline Shader
Hallo, Im using the Shader of http://www.unifycommunity.com/wiki/index.php?title=3DText
The Shader: 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 On Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha Pass { Color [_Color] SetTexture [_MainTex] { combine primary, texture * primary } } } }
Now I was wondering if there is a way to modify this Shader to make a outline around the 3Dtext.
That is my problems too. If anyone knows how to implement it, please help. I am dark in shader.
Help.
Answer by x4000 · Sep 23, 2010 at 07:06 PM
If performance isn't a concern (heh), the way that I've solved this in the past is to draw the text five times. Basically, given a BorderColor and a InnerColor, if you want to draw at X, Y, Z the pseudocode is:
Draw Font with BorderColor at X-1, Y, Z-1
Draw Font with BorderColor at X+1, Y, Z-1
Draw Font with BorderColor at X, Y-1, Z-1
Draw Font with BorderColor at X, Y+1, Z-1
Draw Font with InnerColor at X, Y, Z
That obviously increases the load of drawing the text 5X, but sometimes in menus or for a small amount of text that is not really a worry. We do that in our Unity 3D game Tidalis, for example. It works with 3DText or render text, either way.
One caveat is that sometimes with certain fonts this may not look very good because of the borders being offset poorly. In those cases, you can do an (even more expensive) 9-stage draw process, as follows:
Draw Font with BorderColor at X-1, Y, Z-1
Draw Font with BorderColor at X+1, Y, Z-1
Draw Font with BorderColor at X, Y-1, Z-1
Draw Font with BorderColor at X, Y+1, Z-1
Draw Font with BorderColor at X-1, Y-1, Z-1
Draw Font with BorderColor at X+1, Y+1, Z-1
Draw Font with BorderColor at X+1, Y-1, Z-1
Draw Font with BorderColor at X-1, Y+1, Z-1
Draw Font with InnerColor at X, Y, Z
Talk about inefficient, but it looks really awesome in most cases. With a thick font, you can even do extra large borders (more than 1px) by simply using a variable in place of all those 1 consts for X and Y.
You can of course combine this with something like a RenderTexture, and then save the result for later use as a single texture, when performance is a concern (as it usually is). That way, if you're spending either 5x or 9x the normal render time for a single frame, that's no concern for any game -- then after that it's got a simple prerendered texture of the text, which would be more efficient than using the 3D text to draw the same string, anyway, to my knowledge.
So, despite the poor performance of this at first glance, there are tricky ways you can go about making it perform well. Granted, I'd love to have something simpler and without the need for these sorts of secondary steps, but this is the best I've been able to find to meet my own similar needs.
Where would this 'Draw Font with BorderColor' be placed?
Answer by Kiloblargh · Feb 19, 2013 at 07:41 PM
You don't need to modify the shader, just modify the generated font material. Check this out on the script wiki... You should edit a bold version of the font and shrink selection in Photoshop or "stroke inside" rather than adding the outline around the edges, as the font texture letters are already packed as closely as they can be without running onto the next character's space.
Your answer
Follow this Question
Related Questions
Temperature map shader 0 Answers
Shader Edit Help: 2D Outline Coloring 2 Answers
3d text mesh hides plane object 1 Answer
Strange Error: Shader wants normals, but the mesh doesn't have them 3 Answers
Combine Shaders 0 Answers