What colors does Texture Sample output in a Material

I’m trying to match colors inside a Material and have trouble doing so.

For example, I want to pass a Linear Color to a Material as a parameter and inside match the colors coming from a Texture Sample with the color to replace it or overlay it with an emissive color.

To match colors, I sum up the absolute differences of all components of both colors. This will be compared to some threshold and if at or below this threshold, the texture color is seen as a match.

With my hand drawn texture it works well and I seem to be able to replace colors even with a threshold of 0 (tested with [0,0,0,0], [1,0,0,0] and [2,0,0,0] in RGB values, so veery similar color values).

The problem now is with some textures, some colors do not get matched up to a very high threshold, and when I push up that high, some colors get matched wrongly.

Why is it that for some textures colors can be very accurately matched and for some they cannot? What color values does the Texture Sample node output?

The “Sampler” setting in the Texture Sample node as well as the texture Compression and sRGB settings have an effect too… Can I somehow just read raw color value from a texture inside a material?

Thanks and cheers!

I managed to somehow multiply and potentiate the color difference to a value that can be somehow matched within a certain threshold without having too many false matches. But somehow I cannot comprehend the necessity of a threshold at all.

If I select one color of a pixel at some UV of some texture, put that into a material parameter and inside the material compare that color to the current color of a texture sample, how can I not be able to match that with 100% accuracy?

I’d love to get a bit of insight on this topic :3

So the thing that affects all this the most is of course sRGB <-> linear conversion. My understanding on this is not peak, sooo…

Does the Texture Sample node output sRGB or linear colors? Does the “sampler” setting affect that? It’s actually tough finding the problems here as I don’t know any actual color differences unless the threshold highlights them or if there is any rounding error or something during conversion…