shader_type canvas_item; uniform bool use_pallete; uniform sampler2D pallete_texture; uniform vec4 tint_color : hint_color = vec4(1.0); uniform float tint_factor : hint_range(0, 1); const float from_u = 0.25; const float to_u = 0.75; const float pal_size = 16f; const float threshold = 0.001; void fragment() { vec4 source_color = texture(TEXTURE , UV.xy); vec3 final_color = source_color.rgb; if (use_pallete){ for (float i = 0f; i < pal_size; i++) { vec4 from_color = texture(pallete_texture , vec2(from_u, i/pal_size)); vec4 to_color = texture(pallete_texture , vec2(to_u, i/pal_size)); if(abs(length(source_color.rgb - from_color.rgb)) < threshold) final_color = to_color.rgb; } } COLOR.rgb = mix(final_color, tint_color.rgb, tint_factor); COLOR.a = source_color.a; }