- Home /
Changing text color based on background to make readable
I want to simulate a progress bar, but have text over it, similar to homeworld 2's style. How would i do this? Here is an example: Notice how the text changes as the status bar grows over the text, compare both status bars for the build queue:
I'm no shader expert, so I'd just say, this sounds like a shader issue. I can't really give you an answer, but you need something that does blending like the Pro shader "Hidden/Blend$$anonymous$$odesOverlay". Something that would XOR with the existing color would also give you a similar effect.
Hmm, i cant get my 3d text game object to show any text. i put z offset to 0, and transform.position is all zero. How do specify my text location?
The transform position shouldn't matter at all (except for placement). You need to set up the 'text' field in the text$$anonymous$$esh component to show what text you need, and the renderer needs to have the correct material.
Is anything showing up? It is possible that the 'font size' is too small (in fact, you should increase this to about 100 so that you have smooth text, and then use transform scaling to manage the actual size).
Answer by syclamoth · May 16, 2012 at 12:56 AM
Here's a shader you can use on a 3dText object! It won't work on UnityGUI, of course.
Shader "GUI/ReverseFont" {
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 }
Pass {
Color [_Color]
AlphaTest Greater 0.5
Blend SrcColor DstColor
BlendOp Sub
SetTexture [_MainTex] {
combine previous, texture * primary
}
}
}
}
How would I use this? Just make a 3d text obj then assign this shader as the texture? Is there a nice tutorial for shaders i can try and learn?
Nice tutorial for shaders? I haven't found one. In this case, just make a new shader asset in the project view, and copy-paste this whole thing into it. To connect it to an actual text object is a bit less straightforward- you can't actually do it on the default font (because you can't access the font texture). Just get a nice font from somewhere, and then make a new material, set its shader to this one, change its texture to the font texture, and then you can use the material as a font material with a 3dText object (assu$$anonymous$$g that object is using the same font, of course).
Now that I think about it, this won't work against 62% grey. Just thought I should warn you.
Nice, thanks for that - I really must learn some shader program$$anonymous$$g :)
Your answer
