Two free Godot 4 shaders you can paste in now: hit flash and dissolve
Short answer
In Godot 4, add a ShaderMaterial to a Sprite2D, create a new Shader and paste one of the shaders below. Animate the uniform from GDScript with material.set_shader_parameter("flash", value) or a Tween. Both work in Forward+, Mobile and Compatibility renderers.
Copy-paste code
hit_flash.gdshader and dissolve.gdshader (Godot 4)
// hit_flash.gdshader
shader_type canvas_item;
uniform float flash : hint_range(0.0, 1.0) = 0.0;
uniform vec4 flash_color : source_color = vec4(1.0);
void fragment() {
vec4 tex = texture(TEXTURE, UV);
COLOR = vec4(mix(tex.rgb, flash_color.rgb, flash), tex.a);
}
// dissolve.gdshader (assign any NoiseTexture2D to `noise`)
shader_type canvas_item;
uniform sampler2D noise;
uniform float amount : hint_range(0.0, 1.0) = 0.0;
uniform float edge : hint_range(0.0, 0.2) = 0.05;
uniform vec4 edge_color : source_color = vec4(1.0, 0.5, 0.1, 1.0);
void fragment() {
vec4 tex = texture(TEXTURE, UV);
float n = texture(noise, UV).r;
if (n < amount) { discard; }
float glow = 1.0 - smoothstep(amount, amount + edge, n);
COLOR = vec4(mix(tex.rgb, edge_color.rgb, glow * step(0.001, amount)), tex.a);
}
# GDScript: flash for 0.1 s when hit
func hit() -> void:
var t := create_tween()
material.set_shader_parameter("flash", 1.0)
t.tween_method(func(v): material.set_shader_parameter("flash", v), 1.0, 0.0, 0.1)Good to know
If several sprites share the material, make it unique (Resource > Local To Scene) or every enemy flashes together.
The dissolve needs a noise texture: New NoiseTexture2D with a FastNoiseLite works.
Shadewren Shaders: 17 game shaders for Godot 4, tested
from $8Shadewren is 17 tested Godot 4 shaders (outline, hit flash, dissolve, palette swap, glow, hologram, wind sway, 2D water, CRT, shockwave, toon, stylized 3D water and more), each rendered in Godot 4.4 before release.
Secure checkout · 14-day fix-or-refund if it doesn't work as described (terms)Questions
Does this work in Godot 3?
Godot 3 uses hint_color instead of source_color and a slightly different syntax; these are written for Godot 4.
Can I use it in 3D?
These are canvas_item (2D) shaders; 3D needs a spatial shader.
Free: the Roblox Starter Kit
7 free Luau modules (damage, pets, shop formatting, admin audit log, tycoon guards and more) plus 3 free calculators, then 5 short emails with the scripting fixes we see go wrong most often.