Here's the back story: I was working on a product visualization for a client and they sent me a PDF of the product label with the note "everything displayed in yellow will be printed with a gold foil application". I would have made a quick mask with a photo editor app but I knew the design will change frequently until it is finalized so I wanted to create a chroma key / color mask inside the shader node tree. You would think this is as easy as using one of the many nodes Blender has to offer? Turns out, you have to do a little bit of work . And this video shows what I came up with.
For anyone coming here after they've updated to 4.1, the "HSV" node thing at around 1:26 has been modified. It will no longer be titled "Separate HSV". Instead, use the "Separate Color" node, and there will be a stand-in drop down where you can pick HSV as an option. Great Tutorial btw, lucky to have found it here. Good luck to you guys.
This can be greatly simplified with the compare function in the math node. The epsilon replaces the add and subtract nodes, and you don't need the less than and greater than nodes either. Its all done in one node. 5 nodes vs 20 altogether
I was so focused on explaining WHY that I forgot to think about optimizing the node tree... Using the compare node + blurring the mask here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-mqaa8eUqJts.html
It's a bit hard to spell out the whole noodle setup in a RU-vid comment, but for a feathered mask (softer transition between selected and unselected), you use the vector math Distance node to get the distances between colors (if you wanna measure in HSV space, plug a Separate HSV into a Combine XYZ node to "convert"), and you can control the influence of each component by multiplying the vectors of both the image and the selected color by a same vector before they go into the Distance node, and the overall intensity of the curve can be controlled with math or float curve (or gradient, or map range etc) after the Distance node. Oh, and don't forget to cap the value to the 0-1 range before using it as a Mix factor or whatever.
if you want something even easier just dot product an RGB with the color attribute and use "greater than" or contrast adjust to get the color mask; similar colors will return white from the dot
I'll elaborate because I'm bored, I was creating a stoplight texture and realized I wanted to animate an emission property, only emitting the red, green, and yellow hues. Turns out this was the solution to that equation, and by using a mix node on the original image(ColorA), with a multiply setting(node), comboed with your nodes(ColorB), inputted into emission on BSDF, gave me the solution I was looking for. Your solution even gave me a quick mask for the glassy part of the stoplight.
I have a node setup which converts the rgb signal to LAB format and it gives really interesting results when I do something similar, but I need to do a different kind of distance function
In PS add an image and a hue layer in difference mode. all black now. Change the hue in one color with the slider and at the bottom set the range. Now what do you see? Use this in blender an you're done.