2D Hit Flash (color, amount, optional pulse)

A tiny canvas_item shader for the classic “sprite flashes white (or any color) when hit.” Tween `flash_amount` from 0 to 1 and back on a take-damage signal. Turn on `pulse` for an idle or invincibility blink. Alpha of the original sprite is preserved, so transparent backgrounds stay clean.

 

USAGE:

Add a ShaderMaterial to a Sprite2D or TextureRect, assign this shader, and tune the uniforms in the Inspector:

 

  • `flash_color` — the flash color (default white)
  • `flash_amount` — 0 = normal sprite, 1 = solid flash color
  • `pulse` — if on, `flash_amount` is multiplied by a sine over time
  • `pulse_speed` — blink rate when `pulse` is on
  • `add_mode` — off = lerp to `flash_color`; on = add the flash on top

 

Example:

 

# on take-damage

sprite.material.set_shader_parameter(“flash_amount”, 1.0)

var tw := create_tween()

tw.tween_property(sprite.material, “shader_parameter/flash_amount”, 0.0, 0.15)

 

Works in Godot 4.3+ (Compatibility, Forward+, Mobile).

 

AI-assisted (code + text)

 

Need swings, impacts and spells to trigger the flash? Fantasy RPG SFX Bundle: https://assetsmithpixels.itch.io/fantasy-rpg-sfx-bundle

Shader code
// 2D Hit Flash for Godot 4
// (c) 2026 assetsmithpixels — MIT License
shader_type canvas_item;
render_mode unshaded, blend_mix;

group_uniforms Flash;
uniform vec4 flash_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
// 0 = normal sprite, 1 = solid flash color (alpha preserved).
uniform float flash_amount : hint_range(0.0, 1.0) = 0.0;
uniform bool pulse = false;
uniform float pulse_speed : hint_range(0.0, 32.0) = 10.0;
uniform bool add_mode = false; // if true, add flash on top instead of replacing

void fragment() {
	vec4 sprite = texture(TEXTURE, UV) * COLOR;
	float amt = flash_amount;
	if (pulse) {
		amt *= 0.5 + 0.5 * sin(TIME * pulse_speed);
	}
	vec3 flashed;
	if (add_mode) {
		flashed = sprite.rgb + flash_color.rgb * amt * flash_color.a;
	} else {
		flashed = mix(sprite.rgb, flash_color.rgb, amt * flash_color.a);
	}
	COLOR = vec4(flashed, sprite.a);
}
Live Preview
Tags
2d, blink, canvas item, damage, godot 4, hit flash, sprite
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from assetsmith

Related shaders

Comments 0

No comments yet.