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 code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Radial Progress Shader

Sprite Perspective Correection

Play with Furcifer sprite deformation shader

guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Anaflexys
Anaflexys
1 day ago

the shader affects the whole sprite as in not only the actual thing with color and shape but the png background as well

Anaflexys
Anaflexys
1 day ago

that issue is only for the godot 4.0 code :/