I'm trying to make a shader that takes a color as an input, finds all its occurrences in a texture, and makes a mask out of it.
I have something that seems to work in editor, it makes the selected color black, and then using "Compare with Range" (RangeMin=(0,0,0,255), RangeMax=(1,1,1,255)) , because for some reason the color "black" being returned from the math operations isn't (0,0,0) but (1,0,1), I can make everything that isn't in that range black and make everything that is in that range white. So It seems to me like my masking logic should work. But I get very odd results in practice:
Without Replacing Color: https://imgur.com/a/dcrmMfW
Replacing Color Red with Blue: https://imgur.com/a/uIrhtSA - Works great! All areas that aren't that color should be black.
Like I said works like I expect it to. Now using the
mask we got we can invert it and multiply it by the input texture so that the areas that haven't been replaced aren't just black: https://imgur.com/a/efu6K9c
Replacing color but then using inverted mask to add back unchanged colors: https://imgur.com/a/RqSjNeL
Why is there leaking?? Shouldn't my mask consists of only pure whites and pure blacks?
Does anyone know how to fix this/ have an alternative for color replacement?
After tinkering a bit more this yields "not terrible" results. Had to disable compression on the texture:
Shader: https://i.imgur.com/xLSi65B.png - Gray Scale is Classic old school.
The reason I say it's not terrible is because I'm checking the UV maps of the book and color that I am replacing appears on top of the book too. However that is not being replaced.
I'm closer but there's still some sort of leaking happening...
Somehow Compare With Range is returning a color that isn't white or black: https://i.imgur.com/Gf5kd93.png
- Unreal Engine