New to shaders. Need help for color swapping.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 9BitStrider

I have a set of sprites that I want to be able to change the color or based on the player’s actions. There are 3 colors that I want to allow to be changed (RGB Values of 15,15,15 65,65,65 and 115,115,115) while ignoring the rest. What would be the best way to implement this? And can I see a little example to give me a kick in the right direction?

The idea I have is kinda like this:

if weapon_id == [Insert Weapon ID# here]:
      Change color
:bust_in_silhouette: Reply From: flurick

There is modulate = Color(0.0, 0.1, 0.5, 1.0) which I hope suffice in this case

When I use this, the entire sprite color is changed. I want to be able to change certain pixel color to another using a shader.

This is my shader code:

shader_type canvas_item;

//Set target colors.
uniform vec4 target_color_1 : hint_color;
uniform vec4 target_color_2 : hint_color;
uniform vec4 target_color_3 : hint_color;

//Set replacement colors.
uniform vec4 replace_color_1 : hint_color;
uniform vec4 replace_color_2 : hint_color;
uniform vec4 replace_color_3 : hint_color;

void fragment() {
	if (COLOR == target_color_1)
		COLOR = replace_color_1
	if (COLOR == target_color_2)
		COLOR = replace_color_2
	if (COLOR == target_color_3)
		COLOR = replace_color_3

The above works in the scene editor, but when testing the app, nothing happens. I need a way to trigger this change using GDscript.

9BitStrider | 2018-10-20 15:34