How do I divide a sprite into colored bars using a shader?

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

So I’m using a canvas item shader with the fragment function, and I’m trying to make it so that different sections of the player sprite are a different color based on each pixel’s y position relative to the said player sprite (in other words, I am not trying to use each pixel’s position in the world. I’m trying to divide the sprite into bars, each with their own color). This is proving more difficult for me than I expected. Here’s what I have:

shader_type canvas_item;

void fragment() {
   vec4 previous_color = texture(TEXTURE, UV);
   vec4 pink = vec4(vec3(216.0/255.0, 9.0/255.0, 126.0/255.0), previous_color.a);
   vec4 purple = vec4(vec3(140.0/255.0, 87.0/255.0, 156.0/255.0), previous_color.a);
   vec4 blue = vec4(vec3(36.0/255.0, 70.0/255.0, 142.0/255.0), previous_color.a);

   if(UV.y >= 0.6) {
	  COLOR = pink;
  }

}

This just results in a white rectangle. Any help would be greatly appreciated!