Material function for color similarity?

So I want to make a masked material using a custom color as the “masked” color. My mind is drawing a blank though. For the mask I need to lerp between 0…1 where 0 represents if the texture color equals the masked color and 1 represents if it does not…

I’m not sure how I can determine how “close” colors are to one another with the inputs of “texture color” and “masked color”… I’m sure there is probably something that already does this but I’m drawing a blank.

My texture I’m using has a pink (255,0,255) background and I want to use that as the “masked” color. I don’t want to simply do a compare though to where there is a mask if they are EQUAL but I want to use a bias so I need to figure out how “close” they match.


For a simple comparison like that you can just subtract one color from another. If they are equal the result will be 0, otherwise anything >0 up to 1 per color channel.
Use an ‘Abs’ node afterwards which will return only absolutes so you don’t have any negative numbers.