Hey guys, I got a quick version of this working.
The quickest way to get a clean comparison is by normalizing both your source image and chroma key before comparing them. That will let you discriminate based purely on color without brightness (I just learned this after my first attempt didn’t pick up the monkey’s blanket).
Chroma Key material setup:
random test image:
With replacement color:
And this is the result when you don’t normalize the colors first, things like the blanket will not be caught:
the Power by 2.2 on the color is since the colorpick value needed to be conveted to srgb space, but it only matters when not normalizing.
Obviously with a bit more work you can create a mask to darken or “premultiply” the underlying color. I had it working but the graph got a bit noisy for a screenshot. Basically just use the mask after ‘alpha offset’ to lerp between 1 and your new color and multiply that by the original image before the final lerp.
That will fix the fact that his fair is now too bright at the edges since the green background contributed more brightness than the new red one would have.