how to invert Alpha channel at runtime?

I need a script that inverts the alpha channel of a texture when I trigger it.

I have a energy pipeline on the floor. I use for this pipeline a transparent cutout shader.
when I activate a button the cutout slider will be animated and the gradient alpha will make the pipeline texture visible from point A going to point B.(looks like a river of energy that has started to flow to point B)

now if I deaktivate the button the cutout slider will be animated backwards and now it looks like the energy is running back from point B to point A… but I want that it looks like that no energy is comming from point A to point B. so I need to invert the alpha befor it animates the cutout slider.

please help. thx.

There are two other, simpler possibilities, besides messing with the texture’s alpha directly:

  • Create another texture in your favorite image manipulation program that already has an inverted alpha, and then simply switch between these two textures. This is probably the best solution if you only have one or few source textures.
  • Adapt the shader you are using so that it inverts the alpha when reading from the texture.