Material->Shader doesn't work on some elements?

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

I am adding a shader to the Material option of an Image, and also of a TextureButton to allow making the image or button greyscale when needed. (Godot 3.5) The “Greyscale” radio box appears in the editor, and I can turn the shader on and off manually and it works fine.

Greyscale shader

How do I activate/deactivate the shader correctly in code? This doesn’t seem to work. I thought it was at times, but now it is not. I am not sure what I am doing wrong.


In case it matters, here’s the code I am using, it was from another post here I believe:

shader_type canvas_item;
uniform bool grayscale = false;

void fragment() {
    COLOR = texture(TEXTURE, UV);
    if (grayscale) {
	    float avg = (COLOR.r + COLOR.g + COLOR.b) / 3.0;
	    COLOR.rgb = vec3(avg);
:bust_in_silhouette: Reply From: Ninfur

There seems to be a typo, could that be why it’s not working?

set_shader_param(“greyscale”, true)


uniform bool grayscale = false;

OMG! I spent hours on that. Thats literally all it was. UK / US spelling strikes again.

JayFi | 2022-06-20 12:44