Pixel Art Explosion Shader (2D)

A pixel art explosion in a square: a white flash, a lumpy fireball cooling from yellow to dark red, grey smoke with a dithered edge and a dark outline, a thin shock ring and a few sparks. Everything snaps to the art pixel grid.

Put it on a ColorRect (or any CanvasItem without a texture) and set size_px to the node’s size, 192 x 192 for example. pixel_size is how many screen pixels one art pixel covers. Run progress from 0 to 1 over about a second. seed changes the lumps so two explosions don’t match, and frame_rate makes it step like hand-drawn frames. The colors are uniforms if you want a green or blue blast.

My pixel explosion pack on itch is sprite sheets. This shader is a separate small version I wrote to match it, same white-to-red fire and grey smoke. It looked the same on Forward+, Mobile and Compatibility in 4.4 and 4.7.

The code was written with the help of an AI coding assistant.

The free version of the sprite sheet pack is the first link and the full pack is the second.
https://gennai.itch.io/arcbit-explosion-lite?utm_source=godotshaders&utm_medium=referral&utm_campaign=pixelboom
https://gennai.itch.io/arcbit-explosion-smoke-vfx?utm_source=godotshaders&utm_medium=referral&utm_campaign=pixelboom

Shader code
// Pixel Art Explosion (2D) for Godot 4
// MIT License. Copyright (c) 2026 gennai (https://gennai.itch.io)
//
// A pixel-art explosion that fills a square: a white flash, a lumpy fireball that cools
// from yellow to orange to dark red, a grey smoke cloud with a dithered edge and a dark
// outline, a thin shock ring and a handful of flying sparks. Everything snaps to a grid of art
// pixels, so it matches pixel-art sprites. Put it on a ColorRect (or any CanvasItem with no
// texture) and set the shader's size_px to the same size as the node, for example 192 x 192.
//
// pixel_size is how many screen pixels one art pixel covers (4 = each art pixel is 4 x 4
// screen pixels). Keep it the same as your other sprites. Animate progress from 0 to 1 over
// about one second. seed changes the lumps, so two explosions do not match. The animation
// moves in steps (frame_rate per second), like hand-drawn frames. The colours are plain
// uniforms, so a green or blue explosion only needs new colours.
// No textures: the pattern is computed in the shader with sin-free hashes, so it looks the
// same on every renderer.
shader_type canvas_item;

group_uniforms setup;
// Size of the node in screen pixels. Set this to the node's size.
uniform vec2 size_px = vec2(192.0, 192.0);
// Screen pixels per art pixel. Use a whole number.
uniform float pixel_size : hint_range(1.0, 16.0, 1.0) = 4.0;

group_uniforms explosion;
// 0 = the blast starts, 1 = nothing is left. Animate this.
uniform float progress : hint_range(0.0, 1.0) = 0.3;
// Number of animation steps per second (0 = smooth).
uniform float frame_rate : hint_range(0.0, 30.0) = 12.0;
// How lumpy the outline is.
uniform float lumpiness : hint_range(0.0, 1.0) = 0.4;
// How many sparks fly out.
uniform int spark_count : hint_range(0, 24) = 14;
// Changes the lumps and the sparks.
uniform float seed : hint_range(0.0, 100.0) = 0.0;

group_uniforms palette;
uniform vec4 color_white : source_color = vec4(1.0, 0.97, 0.85, 1.0);
uniform vec4 color_yellow : source_color = vec4(1.0, 0.8, 0.2, 1.0);
uniform vec4 color_orange : source_color = vec4(0.98, 0.45, 0.08, 1.0);
uniform vec4 color_red : source_color = vec4(0.6, 0.12, 0.08, 1.0);
uniform vec4 color_smoke_light : source_color = vec4(0.6, 0.58, 0.58, 1.0);
uniform vec4 color_smoke_dark : source_color = vec4(0.36, 0.35, 0.37, 1.0);
uniform vec4 color_outline : source_color = vec4(0.2, 0.19, 0.22, 1.0);

const float PE_BAYER[16] = float[16](0.0, 8.0, 2.0, 10.0, 12.0, 4.0, 14.0, 6.0, 3.0, 11.0, 1.0, 9.0, 15.0, 7.0, 13.0, 5.0);

float pe_hash(vec2 p) {
	vec3 p3 = fract(vec3(p.xyx) * 0.1031);
	p3 += dot(p3, p3.yzx + 33.33);
	return fract((p3.x + p3.y) * p3.z);
}

float pe_noise(vec2 p) {
	vec2 i = floor(p);
	vec2 f = fract(p);
	f = f * f * (3.0 - 2.0 * f);
	return mix(mix(pe_hash(i), pe_hash(i + vec2(1.0, 0.0)), f.x),
			mix(pe_hash(i + vec2(0.0, 1.0)), pe_hash(i + vec2(1.0, 1.0)), f.x), f.y);
}

float pe_bayer(vec2 p) {
	ivec2 q = ivec2(mod(p, 4.0));
	return (PE_BAYER[q.x + q.y * 4] + 0.5) / 16.0;
}

void fragment() {
	vec2 dim = floor(size_px / pixel_size);
	vec2 art = floor(UV * size_px / pixel_size);
	vec2 c = art + 0.5 - dim * 0.5;
	float R0 = min(dim.x, dim.y) * 0.5;
	float t = progress;
	if (frame_rate > 0.0) {
		t = floor(t * frame_rate * 1.5 + 0.0001) / (frame_rate * 1.5);
	}
	float len = length(c);
	float r = len / R0;
	vec2 dir = len > 0.001 ? c / len : vec2(1.0, 0.0);
	float s = seed * 3.7;

	// the fireball swells fast and slows down
	float grow = 1.0 - pow(1.0 - clamp(t * 1.7, 0.0, 1.0), 3.0);
	float Rf = 0.12 + 0.62 * grow;
	float lump = pe_noise(dir * 2.4 + s) * 0.7 + pe_noise(dir * 5.0 + s * 2.0) * 0.3 - 0.5;
	float rr = r * (1.0 + lump * lumpiness * 1.4);
	float n = pe_noise(art * 0.28 + s);
	float burn = clamp((t - 0.12) / 0.5, 0.0, 1.0);
	float heat = 1.0 - rr / max(Rf, 0.001) - burn * 0.95 + (n - 0.5) * 0.35;

	vec4 col = vec4(0.0);

	// smoke cloud: solid grey with a dithered rim and a dark outline
	float Rs = Rf * 1.08;
	float sd = 1.0 - rr / max(Rs, 0.001);
	float smoke_on = smoothstep(0.08, 0.4, t) * (1.0 - smoothstep(0.78, 1.0, t));
	float dens = sd * 2.2 * smoke_on + (n - 0.5) * 0.4 * smoke_on;
	if (smoke_on > 0.01) {
		if (sd > -0.07 && sd < 0.0) {
			col = color_outline;
		} else if (dens > pe_bayer(art)) {
			float lit = dot(dir, normalize(vec2(-0.5, -0.8)));
			col = lit * (1.0 - rr / max(Rs, 0.001)) > 0.12 - 0.2 * n ? color_smoke_light : color_smoke_dark;
		}
	}

	// fireball on top of the smoke, cooling from white to red
	float fire_end = 1.0 - smoothstep(0.55, 0.75, t);
	if (heat > 0.0 && fire_end > 0.0) {
		float h = heat * (0.55 + 0.45 * fire_end);
		if (h > 0.68) {
			col = color_white;
		} else if (h > 0.46) {
			col = color_yellow;
		} else if (h > 0.26) {
			col = color_orange;
		} else if (h > 0.08) {
			col = color_red;
		}
	}

	// shock ring, only at the start
	float ring_t = clamp(t / 0.4, 0.0, 1.0);
	float ring_r = (0.2 + 0.85 * (1.0 - pow(1.0 - ring_t, 2.0))) * R0;
	if (t < 0.4 && abs(len - ring_r) < 0.75 && (1.0 - ring_t) > pe_bayer(art)) {
		col = color_yellow;
	}

	// flying sparks: single pixels that shoot out and fall back
	for (int i = 0; i < 24; i++) {
		if (i >= spark_count) {
			break;
		}
		float fi = float(i);
		float a = pe_hash(vec2(fi, s)) * TAU;
		float sp = 0.45 + 0.55 * pe_hash(vec2(fi, s + 5.0));
		float life = 0.45 + 0.5 * pe_hash(vec2(fi, s + 9.0));
		float tt = t / life;
		if (tt < 1.0) {
			float dist = (1.0 - pow(1.0 - tt, 2.0)) * sp * R0 * 0.95 + 2.0;
			vec2 pos = vec2(cos(a), sin(a)) * dist + vec2(0.0, tt * tt * R0 * 0.25);
			if (floor(pos) == floor(c)) {
				col = tt < 0.55 ? color_yellow : color_orange;
			}
		}
	}
	COLOR = col;
}
Live Preview
Tags
2d, canvas item, dither, explosion, fire, pixel-art, retro, shader, Smoke, vfx
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 gennai

Related shaders

Comments 0

No comments yet.