Fading color override effect

Changing the delta from a gd script, allows the canvas item to completely display another color keeping the alpha of the base image and control it with a script.

Here’s the gdscript I use for my game in order to control the delta of the shader:

@tool
class_name OverrideColorActivator
extends Sprite2D

@export var activate: bool = false
@export var effect_duration: float = 0.2
var chrono: float = 0.;

func _process(delta):
	if activate == true:
		activate = false
		chrono = effect_duration
	if chrono >= 0:
		var shader_delta: float = chrono/effect_duration
		material.set_shader_parameter("blend_delta", shader_delta)
		chrono -= delta

Have fun!

Shader code
shader_type canvas_item;

uniform vec4 color_override: source_color;
uniform float blend_delta: hint_range(0., 1.0, 0.02) = 0.;

vec4 override_blend_alpha(vec4 base, vec4 blend)
{
	blend.a = base.a;
	return blend;
}

void fragment()
{
	vec4 texture_color = texture(TEXTURE, UV);
	vec4 blend_override = override_blend_alpha(texture_color, color_override);
	vec4 target_color = mix(texture_color, blend_override, blend_delta);
	COLOR = target_color;
}
Tags
ColorOverride, Feedback, HitFX
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

color splash (show only one color)

Loading effect (color over grayscale)

Post-Processing, Grain PP effect and Palette Color

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments