Need help using a 2d shader

Godot Version

4.5

Question

I’ve just started using shaders in godot and I added this shader 2D dissolve with burn edge - Godot Shaders to my animatedsprite2d and everything went well and the shader works fine, but now I can’t change this value of the modulate as you can see in the given photo picture. The code for this shader is in the link. Does anyone know how can I do this?

You could add a modulate to the shader

shader_type canvas_item;

uniform sampler2D dissolve_texture : source_color;
uniform float dissolve_value : hint_range(0,1);
uniform float burn_size: hint_range(0.0, 1.0, 0.01);
uniform vec4 burn_color: source_color;
uniform vec3 modulate_color: source_color; // modulate uniform

void fragment(){
    vec4 main_texture = texture(TEXTURE, UV);
    vec4 noise_texture = texture(dissolve_texture, UV);
	
	float burn_size_step = burn_size * step(0.001, dissolve_value) * step(dissolve_value, 0.999);
	float threshold = smoothstep(noise_texture.x-burn_size_step, noise_texture.x, dissolve_value);
	float border = smoothstep(noise_texture.x, noise_texture.x + burn_size_step, dissolve_value);
	
	COLOR.a *= threshold;
	                                    // multiply by modulate color
	COLOR.rgb = mix(burn_color.rgb, main_texture.rgb * modulate_color, border);
}

I do not see an attached photo

1 Like

Oh sorry, I guess it didn’t work the first time here it is

I just tried doing this and got this erro, Error at line 18: Unknown identifier in expression: ‘modulate_color’.

Did you include the uniform definition?

1 Like

huh, I thought I did but trying this again I didn’t get the error, so I guess I didn’t. But after doing this the sprite is inviable now. I just replaced the all the shaders code with what you posted

What do your shader parameters look like? did you change any other settings, modulating a vec3 should not affect alpha.

1 Like

they are all default and changing the alpha doesn’t do anything. I don’t think its alpha anyway because parts of the shader still show up when sliding the shader from 1 to 0 but no actual sprite can be seen.

The default vec3 is 0, or pure black. You are modulating it black by leaving the uniform module_color as default.

1 Like

oh wait I fixed it

yea that was the problem I didn’t see that until now. I though it would be were the old module was but its this new one

thanks for working though this with me you were huge help!

1 Like

Oh hey, how do I set the modulate brightness now? Because this doesn’t work anymore animated_sprite_2d.modulate.v = 2 doesn’t work anymore

Yeah it’s a totally different parameter for shader uniforms, part of the ShaderMaterial. The sample I posted named the uniform modulate_color, but it has no actual ties to the modulate property.

animated_sprite_2d.material.set_shader_parameter("modulate_color", Color(2, 2, 2))
1 Like