SetShaderParameter Not Working as Expected

Godot Version

4.2.2.stable.mono

Question

Hello, I am trying to change the opacity of a mesh by changing its opacity through a shader.

Here is the shader

shader_type spatial;
render_mode depth_prepass_alpha; 

uniform float opacity:hint_range(0.0, 1.0) = 1.0;
uniform sampler2D _abeldo:source_color;

void fragment() {
	ALBEDO = texture(_abeldo, UV).rbg;
	ALPHA = opacity;
}

I have function that sets opacity

public void SetOpacity()
{
	mesh.SetInstanceShaderParameter("opacity", opacity);
}

but the opacity never changes.

If I print

mesh.GetInstanceShaderParameter("opacity", opacity);

It prints out the value I expect it to be, but that opacity is not reflected in the scene. I have no Idea why that would be, and if anyone can see a mistake that I am making please let me know.

If you want to use instance shader parameters, you should declare that as instance uniform in your shader code.

1 Like

This was exactly it, thanks a ton! Iā€™m new to shaders so thank you for answering my elementary question!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.