I have a RGB color in the range of 0.0 to 1.0 for each fragment, I need an algorithm to get the inverse of the color, any ideas how can I do this?
Colour inversion is achieved by subtracting each RGB colour value from the maximum possible value (usually 255). Another effect which is related to colour inversion is the solarise effect.
Inverting colors in images It does this by inverting the brightness value of each pixel in each color channel. For example, if a pixel is pure red, its brightness levels are 255, 0, 0 in RGB mode. When inverted, this pixel's brightness values become 0, 255, 255, changing it to pure blue-green, its opposite in hue.
xor ( ^ ) with 0 returns the original value unmodified. xor with 0xff flips the bits. so in the above case we have 0xaarrggbb we are flipping/inverting r, g and b. This should be the most efficient way to invert a color.
newR = 1.0 - r newG = 1.0 - g newB = 1.0 - b
If the color has a premultiplied Alpha value use the alpha instead of 1.0:
newR = a - r newG = a - g newB = a - b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With