Ground Crack Shader (Spreading Decal)

Cracks that run out from one point on the floor and get thinner toward the ends. Animate spread from 0 to 1 for a ground slam. With the glow turned up they work as lava cracks.

Lay a flat PlaneMesh (6 x 6 is fine) on the floor. The shader lifts it a few millimetres along its normal so it doesn’t flicker. scale is the size of the slabs between cracks, width is the line thickness and wobble is how much the lines wander. Set glow_color to black for plain dark cracks. My first version glowed so much it looked like a lava field, so the default glow is low now.

No textures, and 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.

I wrote this as a small take on the cracks in my Ground & Rock VFX pack for Godot 4, which also has rock debris, dust and footprints. The free version is the first link and the full pack is the second.
https://gennai.itch.io/free-footstep-dust-vfx-godot-4?utm_source=godotshaders&utm_medium=referral&utm_campaign=crack
https://gennai.itch.io/ground-rock-vfx-godot-4?utm_source=godotshaders&utm_medium=referral&utm_campaign=crack

Shader code
// Ground Crack Decal for Godot 4
// MIT License. Copyright (c) 2026 gennai (https://gennai.itch.io)
//
// Cracks that spread out from one point on the floor. Put this on a MeshInstance3D with
// a flat PlaneMesh (for example 6 x 6) as the mesh, and lay it on your floor, a few
// millimetres above it. The shader pushes the plane a little along its normal so it
// does not flicker against the floor. The centre of the plane is where the cracks start.
//
// Animate spread from 0 to 1 and the cracks run outward from the centre, thinner at
// the ends. Set the node's scale to change how far they reach. seed changes the pattern.
// glow_color adds a hot light inside the cracks (set it to black for plain stone).
// No textures: the pattern is computed in the shader with sin-free hashes, so it looks
// the same on every renderer.
shader_type spatial;
render_mode blend_mix, depth_draw_never, cull_disabled, specular_disabled, shadows_disabled;

group_uniforms crack;
// 0 = no cracks yet, 1 = the cracks have reached the edge of the plane. Animate this.
uniform float spread : hint_range(0.0, 1.0) = 1.0;
// Size of the stone slabs between the cracks. Higher = more cracks.
uniform float scale : hint_range(1.0, 12.0) = 3.5;
// Thickness of the main cracks.
uniform float width : hint_range(0.005, 0.3) = 0.12;
// How much the cracks wander. 0 = straight lines.
uniform float wobble : hint_range(0.0, 1.0) = 0.4;
// How much thinner the cracks get towards the edge.
uniform float taper : hint_range(0.0, 1.0) = 0.7;
// Changes the pattern.
uniform float seed : hint_range(0.0, 100.0) = 0.0;

group_uniforms look;
// Colour inside the cracks.
uniform vec4 crack_color : source_color = vec4(0.015, 0.012, 0.01, 1.0);
// Light inside the cracks, such as lava. Black = none.
uniform vec4 glow_color : source_color = vec4(1.0, 0.35, 0.05, 1.0);
// Brightness of the glow. Values above 1 bloom when glow is on.
uniform float glow_energy : hint_range(0.0, 8.0) = 0.9;
// Darkening around the cracks, like a shadow.
uniform float shadow : hint_range(0.0, 1.0) = 0.55;
// How far the plane is pushed up along its normal, in metres.
uniform float lift : hint_range(0.0, 0.05) = 0.004;

float gc_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);
}

vec2 gc_hash2(vec2 p) {
	return vec2(gc_hash(p), gc_hash(p + 37.7));
}

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

// Distance to the nearest border between two cells.
float gc_cells(vec2 p) {
	vec2 i = floor(p);
	vec2 f = fract(p);
	float d1 = 8.0;
	float d2 = 8.0;
	for (int y = -1; y <= 1; y++) {
		for (int x = -1; x <= 1; x++) {
			vec2 g = vec2(float(x), float(y));
			vec2 o = gc_hash2(i + g + seed);
			float d = length(g + o - f);
			if (d < d1) {
				d2 = d1;
				d1 = d;
			} else if (d < d2) {
				d2 = d;
			}
		}
	}
	return d2 - d1;
}

void vertex() {
	VERTEX += NORMAL * lift;
}

void fragment() {
	vec2 p = (UV - 0.5) * 2.0;
	float r = length(p);
	vec2 w = vec2(gc_noise(p * 4.0 + seed), gc_noise(p * 4.0 + 31.0 + seed)) - 0.5;
	vec2 q = p + w * wobble * 0.5;
	float rn = r + (gc_noise(p * 3.0 + seed * 1.7) - 0.5) * 0.3;
	// The cracks start at the centre and run outward.
	float reach = spread * 1.25;
	float grow = smoothstep(reach, reach - 0.18, rn);
	float tp = 1.0 - taper * clamp(r, 0.0, 1.0);
	float big = gc_cells(q * scale);
	float small = gc_cells(q * scale * 2.3 + 7.0);
	float wd = width * tp;
	float line_big = 1.0 - smoothstep(wd * 0.5, wd, big);
	// Fine cracks only close to the centre.
	float line_small = (1.0 - smoothstep(wd * 0.15, wd * 0.35, small)) * smoothstep(0.4, 0.05, r) * 0.8;
	float crack = max(line_big, line_small * 0.9) * grow;
	float halo = (1.0 - smoothstep(0.0, wd * 3.0, big)) * grow * shadow;
	float edge_fade = smoothstep(1.0, 0.82, r);
	float a = max(crack, halo * 0.6) * edge_fade;
	float inner = crack * (1.0 - smoothstep(0.0, wd * 0.6, big)) * edge_fade;
	ALBEDO = crack_color.rgb;
	ROUGHNESS = 1.0;
	EMISSION = glow_color.rgb * glow_energy * inner * (1.0 - r * 0.6);
	ALPHA = clamp(a, 0.0, 1.0);
}
Live Preview
Tags
3d, crack, decal, earthquake, floor, ground, impact, lava, stone, 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.