Circle jump tutorial shader change color has no effect

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

I’ ve finished the tutorial and I have a working game, but there is a problem from part1 which doesn’t work.
At this part used a color shader in material property of the sprite which changes its color. The code for the shader is:

shader_type canvas_item;
uniform vec4 color : hint_color;
void fragment() {
COLOR.rgb = color.rgb;
COLOR.a = texture(TEXTURE, UV)

On the video after line “COLOR.rgb = color.rgb;”, appears a Color property in the inspector a colorpicker item to change color. Also the sprite’s rectangle changes color. In my case this has no effect in texture’s(or rectangle’s) area. The color doesn’t change.
At a later part the same shader file (which saved as color.shader ) is used to another sprite(a circle) this code:

shader_type canvas_item;

uniform vec4 color : hint_color; 
uniform float speed : hint_range(0,20);
uniform float radius : hint_range(0, 1);
uniform float width : hint_range(0, 1);

void fragment() {
    vec2 center = vec2(0.5);
    float time = TIME * speed;
    float rad = radius - 0.005 * sin(time);
    float thickness = width + 0.05 * cos(time);
    float dist = distance(UV, center);
    COLOR.rgb = color.rgb;
    COLOR.a = texture(TEXTURE, UV).a+smoothstep(thickness/2.0, 0.0, abs(dist-rad));

and there it works fine.
I don’n know which version of godot used in that tutorial, but I have the version: 3.2.3 stable.
Is something changed there?
I have read the comments in youtube and seems that others haven’t problem with this. Only a comment to use to some that the code gives an error(In my case there’s no errors), which suggests to use:

COLOR.r = color.r
COLOR.b = color.b
COLOR.g = color.g

instead, but this also has no effect in my case.
Any ideas?

:bust_in_silhouette: Reply From: exuin

COLOR.a = texture(TEXTURE, UV) is assigning a vec4 to a float. Try COLOR.a = texture(TEXTURE, UV).a.

Sorry, I have it like this. Just when I copied the related code I missed the “.a”.
And it doesn’t work without this line too. When the color assigned it should change the color of the rect of the sprite but it doesn’t to nothing.

It’s nothing wrong with the code. I don’t know how I missed this because I checked and changed every sprite’s property, but the problem was that in “Material” properties there is a property “Use parent” which was checked.
Probably I missed it because is outside the block of the other “Material” properties which is painted with a green color.

dancaer69 | 2021-02-18 17:16