Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Diet Estus |
I am trying to learn shaders in Godot 3.0 using the shading language documentation.
I am a complete novice when it comes to shaders and am trying to create a simple canvas_item
shader which changes the color of certain pixels of my sprite. I’m just trying to do this simple task to learn how things work.
Basically, if the pixel color is above a certain threshold of red, I want to change it to green, otherwise I’ll change it to blue.
I attached the following shader script to a sprite’s ShaderMaterial
, but it doesn’t work as expected. If I set the threshold below 1, the entire sprite is green. If I set the threshold above 1, the entire sprite is blue. It’s not changing things on a pixel-by-pixel basis.
Here is my code:
shader_type canvas_item;
render_mode blend_mix; // not sure if this matters in this example
void fragment(){
// if the pixel has enough red
if (COLOR.r > 100.0){
// set its color to green
COLOR = vec4(0.0, 255.0, 0.0, 255.0);
}
// otherwise
else{
// set its color to blue
COLOR = vec4(0.0, 0.0, 255.0, 255.0)
}
}
What am I doing wrong?