shader_type canvas_item;

uniform vec4 original_0: source_color;
uniform vec4 original_1: source_color;
uniform vec4 original_2: source_color;
uniform vec4 original_3: source_color;
uniform vec4 original_4: source_color;
uniform vec4 original_5: source_color;
uniform vec4 original_6: source_color;
uniform vec4 original_7: source_color;
uniform vec4 original_8: source_color;
uniform vec4 original_9: source_color;
uniform vec4 original_10: source_color;
uniform vec4 original_11: source_color;
uniform vec4 original_12: source_color;
uniform vec4 original_13: source_color;
uniform vec4 replace_0: source_color;
uniform vec4 replace_1: source_color;
uniform vec4 replace_2: source_color;
uniform vec4 replace_3: source_color;
uniform vec4 replace_4: source_color;
uniform vec4 replace_5: source_color;
uniform vec4 replace_6: source_color;
uniform vec4 replace_7: source_color;
uniform vec4 replace_8: source_color;
uniform vec4 replace_9: source_color;
uniform vec4 replace_10: source_color;
uniform vec4 replace_11: source_color;
uniform vec4 replace_12: source_color;
uniform vec4 replace_13: source_color;

uniform vec4 tint: source_color = vec4(1.0);
uniform vec4 ambient: source_color = vec4(1.0, 1.0, 1.0, 1.0);

const float precision = 0.1;
const int Colz = 14;

vec4 swap_color(vec4 color){
	vec4 original_colors[Colz] = vec4[Colz] (
		original_0, 
		original_1, 
		original_2, 
		original_3, 
		original_4, 
		original_5, 
		original_6, 
		original_7, 
		original_8, 
		original_9, 
		original_10, 
		original_11, 
		original_12, 
		original_13
	);
	vec4 replace_colors[Colz] = vec4[Colz] (
		replace_0, 
		replace_1, 
		replace_2, 
		replace_3, 
		replace_4, 
		replace_5, 
		replace_6, 
		replace_7, 
		replace_8, 
		replace_9, 
		replace_10, 
		replace_11, 
		replace_12, 
		replace_13
	);
	for (int i = 0; i < Colz; i ++) {
		if (distance(color, original_colors[i]) <= precision){
			return replace_colors[i];
		}
	}
	return color;
}


void fragment() {
	vec4 col = swap_color(texture(TEXTURE, UV));
	COLOR = col * tint * ambient;
}

void light() {
	// Called for every pixel for every light affecting the CanvasItem.
	float cNdotL = max(1.0, dot(NORMAL, LIGHT_DIRECTION));
  	LIGHT = vec4(LIGHT_COLOR.rgb * COLOR.rgb * LIGHT_ENERGY * cNdotL, LIGHT_COLOR.a);
}
















