I am learning about shaders and want to implement a simple dissolve shader in my 2D game that looks like this:
This is the first step of implementing a more complex shader found here.
So far, all I've been able to come up with is this:
// DISSOLVE SHADER
uniform sampler2D noise_img : hint_albedo;
uniform float dissolve_value : hint_range(0,1);
vec4 main_texture = texture(TEXTURE, UV); // TEXTURE is texture of the sprite the shader is attached to
vec4 noise_texture = texture(noise_img, SCREEN_UV);
// modify the main texture's alpha using the noise texture
main_texture.a *= floor(dissolve_value + min(0.99, noise_texture.x));
COLOR = main_texture;
I am using this noise image:
For dissolve_value = 0.7, I get:
It seems like I am on the right track, but I have a few questions.
First, am I really on the right track?
Second, how does one go about getting the effect to progress over time? The effect should dissolve the sprite over time, but right now, because dissolve_value is static, the effect is just static. How do you add a temporal dimension into the shader?
Third, how do you start and stop shaders? I want to initiate this effect on a node when the node's
enter_death() method is called. How does one go about initiating a shader, and, later, stopping or removing it?