0 votes

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!

Godot version 3.4.1 stable
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.