- Home /
How do I invert the color of ui text to make it more readable, on a messy background?
I want to invert text color against a background, in order to make it more readable.
This is the effect I want (It's a photoshop): I've tried setting the text's material to a material with an inverting shader, and it works, but it makes the text go blocky:
Any ideas on how I should do this?
-Thanks
Answer by Pangamini · Feb 03, 2018 at 01:42 PM
You can create different inversion effects by playing with blend options and the output color (for example, only invert one or two of the channels). For more advanced background processing, you can use unity's GrabPass and have the background accessible in a texture from your shader, but that's far more expensive
Answer by Harinezumi · Feb 05, 2018 at 12:07 PM
I think the best way is to convert the RGB color to HSV space (where the color is in the H value), and invert it, then convert it back:
public static Color Invert(Color rgbColor) {
float h, s, v;
Color.RGBToHSV(rgbColor, out h, out s, out v);
return Color.HSVToRGB((h + 0.5f) % 1, s, v);
}
this would invert the color for the entire text, not just parts of it (as shown in the images).
Oh, it wasn't clear for me that it should only invert part of the image!
Hmmm, inverting only a part, like in the image seems to be more complicated.
@jebthedev, are you using Text$$anonymous$$eshPro for your texts?