Sprite progress bar
Convert any sprite into a progress bar with the help of color overlay.
Shader code
// UPDATED VERSION FOR GODOT 4
shader_type canvas_item;
uniform vec4 overlay_color : hint_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform float progress : hint_range(0.0,1.0) = 0.0;
uniform float strength : hint_range(0.0,1.0) = 0.0;
void fragment() {
vec4 custom_color = texture(TEXTURE, UV);
if (1.0 - UV.y <= progress && custom_color.a != 0.0) {
custom_color.rgb = mix(custom_color.rgb, overlay_color.rgb, strength);
custom_color.a = COLOR.a;
COLOR = custom_color;
}
}
// FOR GODOT 3.X
shader_type canvas_item;
uniform vec4 overlay_color : hint_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform float progress : hint_range(0.0,1.0) = 0.0;
uniform float strength : hint_range(0.0,1.0) = 0.0;
void fragment() {
if (1f - UV.y <= progress) {
vec4 custom_color = texture(TEXTURE, UV);
custom_color.rgb = mix(custom_color.rgb, overlay_color.rgb, strength);
COLOR = custom_color;
} else {
COLOR = texture(TEXTURE, UV);
}
}
the shader affects the whole sprite as in not only the actual thing with color and shape but the png background as well
that issue is only for the godot 4.0 code :/
Yeah so the shader language have been updated for godot 4 so you need different code depending on which version.
But I havn’t tried the latest alpha yet, is it broken if you use the correct version?