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:

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
      }
   }
}
}