Enhanced Dissolve (+ragdoll alternative tutorial)
This is an enhaced version of my previous simple dissolve shder. This time, I’m using also the vertex normal as an hint to do the dissolve effect. It still uses the UV map, but using also the normal gives a nicer effect.
I’ve made this for my YouTube’s “ragdoll alternative for godot” tutorial.
As usual, you can find the full sample project on my github.
Link to the youtube ragdoll alternative tutorial (AI dubbed).
Shader code
shader_type spatial;
//render_mode unshaded;
uniform float t = 0.0; // animation 0 = start, 1 = end
uniform vec3 color_base : source_color = vec3(1.0, 1.0, 1.0);
uniform vec3 color_edge : source_color = vec3(1.0, 0.0, 0.0);
uniform float edge_size = 0.025;
uniform sampler2D noise_tex;
uniform float noise_scale = 1.0;
uniform vec3 axis = vec3(0.0, 1.0, 0.0);
varying vec3 local_nrm;
void vertex() {
local_nrm = NORMAL;
}
void fragment() {
// get value based on dot product against normal
float d = dot(local_nrm, axis); // value from -1 to 1
d = clamp((d + 1.0) * 0.5, 0.0, 1.0); // convert to 0 to 1
// add UV based noise
float noise = texture(noise_tex, UV * noise_scale).r;
float value = d + noise; // value from 1 to 2
value = clamp(value * 0.5, 0.0, 1.0); // convert to 0 to 1
if (value < t)
discard;
value = smoothstep(t, 1.0, value); // (re)convert to 0 to 1
float mix_val = smoothstep(0.0, edge_size, value);
ALBEDO = vec3(0.0);
EMISSION = mix(color_edge, color_base, mix_val);
}
