← Pixel Dreamer Studio

Fireworks without sub-emitters

For the Compatibility renderer, web exports and low-end PCs.

The Compatibility renderer does not support particle sub-emitters: set Sub Emitter Mode to At End and the rockets fly, but nothing bursts. Godot only prints a warning. Fly each rocket from a script instead, and when it stops going up, start a one-shot GPUParticles3D burst at its position. The script below does this and cleans up after itself.

A night sky with three round bursts of small dots in red, blue and yellow, and a faint rocket trail rising in the middle
The script below in Godot 4.7 with the Compatibility renderer, 2.1 seconds after the first of four rockets went up.

What happens with a sub-emitter

We made the usual setup: a rocket GPUParticles3D going up at 14 meters per second with sub_emitter_mode set to SUB_EMITTER_AT_END, and a burst GPUParticles3D set as its sub_emitter. In the Compatibility renderer, Godot printed The Compatibility renderer does not support particle sub-emitters and went on. Over 30 frames after the rockets reached the top, the upper half of the screen never had more than 6 lit pixels: the rockets, and no burst.

The code

Add a Node3D where the rockets go up from, attach this script and call launch(), from a timer, a button or a level event. Connect burst for a sound or a light flash.

extends Node3D
## Fireworks without sub-emitters, which the Compatibility renderer does not support.
## Put this where the rockets go up from and call launch(). Each rocket bursts at the top of its flight.

signal burst(at: Vector3)

@export var speed := 14.0  # m/s at launch: the top is about speed * speed / (2 * gravity) up
@export var gravity := 9.8
@export var tilt_deg := 8.0  # random lean of each rocket
@export var burst_amount := 160
@export var colors: Array[Color] = [Color(1, 0.4, 0.5), Color(0.4, 0.8, 1), Color(1, 0.85, 0.3)]


func launch() -> void:
	var rocket := Node3D.new()
	add_child(rocket)
	var lean := Basis.from_euler(Vector3(deg_to_rad(randf_range(-tilt_deg, tilt_deg)), 0, deg_to_rad(randf_range(-tilt_deg, tilt_deg))))
	var vel := lean * Vector3.UP * speed
	var trail := _particles(24, 0.5, Color(1, 0.8, 0.5), 0.08)
	(trail.process_material as ParticleProcessMaterial).initial_velocity_max = 0.3
	rocket.add_child(trail)
	while vel.y > 0.0:  # fly until it stops going up
		await get_tree().physics_frame
		var dt := 1.0 / Engine.physics_ticks_per_second
		vel.y -= gravity * dt
		rocket.position += vel * dt
	_burst(rocket.global_position, colors.pick_random())
	trail.emitting = false
	await get_tree().create_timer(trail.lifetime).timeout
	rocket.queue_free()


func _burst(at: Vector3, col: Color) -> void:
	var p := _particles(burst_amount, 1.6, col, 0.2)
	var m := p.process_material as ParticleProcessMaterial
	m.spread = 180.0
	m.initial_velocity_min = 4.0
	m.initial_velocity_max = 6.0
	m.damping_min = 1.5
	m.damping_max = 2.5
	m.gravity = Vector3(0, -2.0, 0)
	p.one_shot = true
	p.explosiveness = 1.0
	add_child(p)
	p.global_position = at
	p.finished.connect(p.queue_free)
	p.restart()
	burst.emit(at)


func _particles(count: int, life: float, col: Color, size: float) -> GPUParticles3D:
	var p := GPUParticles3D.new()
	p.amount = count
	p.lifetime = life
	p.local_coords = false
	var m := ParticleProcessMaterial.new()
	m.gravity = Vector3.ZERO
	var g := Gradient.new()
	g.colors = PackedColorArray([col, Color(col, 0.0)])
	var ramp := GradientTexture1D.new()
	ramp.gradient = g
	m.color_ramp = ramp
	p.process_material = m
	var dot := GradientTexture2D.new()
	dot.gradient = Gradient.new()
	dot.gradient.colors = PackedColorArray([Color(1, 1, 1, 1), Color(1, 1, 1, 0)])
	dot.fill = GradientTexture2D.FILL_RADIAL
	dot.fill_from = Vector2(0.5, 0.5)
	dot.fill_to = Vector2(1.0, 0.5)
	var mat := StandardMaterial3D.new()
	mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	mat.blend_mode = BaseMaterial3D.BLEND_MODE_ADD
	mat.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
	mat.vertex_color_use_as_albedo = true
	mat.albedo_texture = dot
	var q := QuadMesh.new()
	q.size = Vector2(size, size)
	q.material = mat
	p.draw_pass_1 = q
	return p

One rocket straight up burst 1.43 seconds after launch, 9.88 meters up (the formula in the comment gives 10). 0.2 seconds later the upper half of the screen had 220 lit pixels. 2.5 seconds later the node had 0 children left: the burst frees itself on finished, and the rocket after its trail is gone.

Many rockets at once

Five rockets launched 0.3 seconds apart with tilt_deg at 8 gave 5 bursts, between 9.66 and 9.86 meters up and between 0.97 and 2.97 meters to the side of the launch point. Every launch is its own coroutine, so they do not wait for each other. After the last burst, 0 nodes were left.

What to change

Remove one-shot effects when they end: remove a one-shot particle effect when it ends. A burst for an explosion instead: explosion particles in one burst.

All four Compatibility gaps in one place: particles not working in a web export.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Festival & Fireworks VFX for Godot 4 has rockets that burst by themselves: Peony, Willow Gold, Ring Cyan, Heart Pink, Star Gold, Palm Green, Finale Barrage and New Year Burst, plus fountains, sparklers and confetti. One-shots start with play().

More how-tos: Fire, smoke and explosions