PVZ-alike Slot cooldown

Shoutout to swagboard for uploading the original Sprite progress bar shader. I used their code as a base and with ChatGPT’s help, I managed to make an alternate version of it.

Usage: 

  • cooldown_bg : color overlay for top portion of the slot when it’s in cooldown
  • bg_overlay_strength : mix factor for cooldown_bg with the base texture UV
  • inactive_color : color overlay for bottom portion of the slot when it’s in cooldown
  • overlay_strength : mix factor for inactive_color with the base texture UV
  • active_color : color to overlay when the slot is selected
  • active_overlay_strength : mix factor for active_color with the base texture UV
  • progress : progress for the cooldown (1 = full, 0 = none i.e. no more cooldown)

Booleans (Important!):

You need to set the right booleans at the right time for the shader to work correctly!

  • cooldown_bg_switch : must be true at first, and then must be set to false when the shader parameter “progress” is <= 0. And it should be set to true again when the slot is planted again and yeah you know the drill.
  • is_active : set this to true when the slot is selected so that it will be highlighted.

I am not very good with naming things so I am sorry if the uniform names are confusing lol.
Feel free to change them in the shader editor.

Shader code
shader_type canvas_item;

uniform vec4 inactive_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 cooldown_bg: source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 active_color : source_color = vec4(1.0, 0.0, 0.0, 1.0);
uniform float progress : hint_range(0.0, 1.0) = 0.0;
uniform float overlay_strength : hint_range(0.0, 1.0) = 0.0;
uniform float bg_overlay_strength : hint_range(0.0, 1.0) = 0.0;
uniform float active_overlay_strength : hint_range(0.0, 1.0) = 0.0;
uniform bool is_active = false;
uniform bool cooldown_bg_switch = true;

void fragment() {
    vec4 custom_color = texture(TEXTURE, UV);
	vec4 cooldown_bg_color = vec4(0,0,0,0);
	if ((1.0 - UV.y >= progress && custom_color.a != 0.0 && cooldown_bg_switch==true) || (is_active==false && cooldown_bg_switch==true)){
		cooldown_bg_color.rgb = mix(custom_color.rgb, cooldown_bg.rgb, bg_overlay_strength);
		cooldown_bg_color.a = COLOR.a;
		COLOR = cooldown_bg_color;
	}
    if (1.0 - UV.y <= progress && custom_color.a != 0.0 && is_active==false) {
        // Mix the overlay color with the original color using overlay_strength
        custom_color.rgb = mix(custom_color.rgb, inactive_color.rgb, overlay_strength);
        custom_color.a = COLOR.a;
        COLOR = custom_color;
    }
	if (custom_color.a != 0.0 && is_active==true)
	{
		custom_color.rgb = mix(custom_color.rgb, active_color.rgb, active_overlay_strength);
		custom_color.a = COLOR.a;
		custom_color.a = COLOR.a;
		COLOR = custom_color;
	}
}
Tags
progress, PvZ, Slot
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 / Cooldown shader

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Cabo Dev
3 months ago

your code is free of copyright?