Algorithm for calculating inverse color

前端 未结 2 620
遇见更好的自我
遇见更好的自我 2021-02-05 03:42

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?

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 04:05

    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
    

提交回复
热议问题