Color ID selector/mask node for cycles materials [SOLVED]

I need exactly this https://docs.blender.org/manual/en/latest/compositing/types/matte/color_key.html but for materials. I want to input a color ID texture (like this https://i.imgur.com/guDVCdY.png), pick a color and have a black and white mask output (0 if the pixel is not that color, 1 if it is). This seems like a pretty basic math operation (just compare numbers and output 1 if “equals to” = true), but I can’t figure out how to set it up in cycles material nodes.

We don’t have a “equal (with tolerance) to” operator. You have to setup a nodegroup where you output 1 if input is:
greater than input - tolerance AND
less than input + tolerance.
Tolerance can be zero, but I always put it in because sometimes it drifts if the source is compressed (i.e. jpg artefacts).
Since we also don’t have logical operators as such, you have to setup that as well.
Then you have to use the node group on all three HSV (or RGB if you prefer) channels and do AND operators on those as well.

A agree fully, a proper ID node would be waaaay preferred, as sometimes I’m not able to have the topology support the texture divisions I want.

Ok, I found the solution. So obvious I feel dumb. It’s just a difference node. Difference mode compares areas and if the difference between colors is 0, it displays black. Then I just need to isolate black from the rest with “less than” (or color ramp, if you need more fluid threshold) and kaboom, ID mask.

1 Like