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:
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
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);
}