Lets say i have an sprite with an image which have three colors - red, green and pink.
Now if i change the color of red part to blue using a shader like this ->
shader_type canvas_item;
uniform vec4 oldColor : hint_color;
uniform vec4 newColor : hint_color;
void fragment(){
vec4 curr_color = texture(TEXTURE,UV);
if(curr_color == oldColor){
COLOR = newColor;
}
else{
COLOR = curr_color;
}
}
It will successfully change , now if i try to change lets say green to yellow, it will also work but it will reset the blue color back to red.
So I think this can be due to that the shader is not updating the actual image, since I am using img.get_pixel() to get the color value where I click and update the oldColor variable of the shader from my gdscript.
So what it is doing is it is seeing that the blue color as red because the actual color on Image may still be red and the blue is just like an overlay.
So how do i update the image so that the colors get updated in the shader as well ?