I can't modify shader uniform with set_shader_param

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

I am new to shaders, so I am probably just missing something obvious.
Anyhow, I am making an RTS style thing, and what I want to do is have a specific colour in a sprite replaced with the player’s colour using a shader material.
The colour is determined by a function based on an export variable inherited by every unit. The function is called when the unit spawns, and just assigns a colour based on the player number by using “material.set_shader_param()”.
The export var is working correctly, but the shader is giving me issues. On the editor, the colour to be swapped, blue, is replaced by black, which is not assigned to the uniform at any point. Furthermore, when I actually run the game, the blue colour is completely transparent! Again, I’ve never told the shader to do this.
I’ve tried to set different values for the new_colour uniform, such as vec4(1,1,1,1), vec4(255,255,255,1) and vec4(255,255,255,255). None seem to have an effect. I also tried to change the uniform into a variable, but this again didn’t bring me any closer to a solution.

Here is the relevant GDS code:

func set_colour():
var gaia = "vec4(255,255,255,1)"
var p1 = "vec4(0.0/255.0,38.0/255.0,255.0/255.0,255)"

match plr:
		print("something should happen")
		print("nothing should happen")

Here is the shader code:

shader_type canvas_item;

uniform vec4 new_colour: hint_color;

void fragment() {

    vec4 current_pixel = texture(TEXTURE, UV);

//	if a pixel is blue, change it to new_colour, otherwise leave it alone
    if (current_pixel == vec4(0.0/255.0,38.0/255.0,255.0/255.0,1))
        COLOR = new_colour;
        COLOR = current_pixel;

As you can see, I do not really even know which kind of syntax the vec4() parameter takes.
Sorry for my poor English!

:bust_in_silhouette: Reply From: sash-rc

Your variables, passed to uniform are of type String, while should be Color.

var clr : Color = Color.darkolivegreen # or whatever
material.set_shader_param("new_colour", clr)

Thank you! As expected, the answer seems really obvious in hindsight.

Kappa Ferro | 2022-02-01 13:11