0 votes

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?

in Engine by (221 points)

1 Answer

+1 vote
Best answer

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

by (8,155 points)
selected by

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.

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.