← Pixel Dreamer Studio

Big particle effects that stay on screen

Make the GPUParticles3D visibility box as big as the space its particles really fly through.

Godot decides whether to draw a GPUParticles3D from its visibility_aabb, a box around the node, not from where the particles are. The default box is 8 m wide, 4 m each way from the emitter. In our Godot 4.7 test, fireworks launched from the ground rose about 26 m. Looking at the base, they were drawn. Looking up at the burst, with the base below the screen, 0 pixels: the box was off screen, so the whole effect was skipped while every spark was in view. The script below watches one lifetime with capture_aabb(), merges the boxes and sets visibility_aabb: 912 to 1,053 lit pixels looking up.

The code

Save it as vis_box.gd and load it with const VisBox := preload("res://vis_box.gd"). In the emitter's _ready(), await VisBox.fit($Fireworks). It restarts the effect and watches it for one lifetime, so do it before the player sees it, or once while you build the scene: print the box it returns and type it into visibility_aabb in the Inspector, so the game never has to wait.

extends RefCounted
## Fit a GPUParticles3D's visibility box to where its particles really go, so the effect
## is not culled while its particles are still on screen (fireworks, tall fire, wide explosions).
##   const VisBox := preload("res://vis_box.gd")
##   func _ready():
##       await VisBox.fit($Fireworks)   # watches one lifetime, then sets visibility_aabb
## Better still: run it once, print the box and paste it into visibility_aabb in the Inspector.


static func fit(p: GPUParticles3D, margin := 1.0) -> AABB:
	var was_emitting := p.emitting
	p.restart()  # one full lifetime from the start, one-shot effects too
	var box := AABB()
	var found := false
	var watch_ms := int(p.lifetime * 1000.0 / maxf(p.speed_scale, 0.01)) + 100
	var end := Time.get_ticks_msec() + watch_ms
	while Time.get_ticks_msec() < end:
		await p.get_tree().process_frame
		var b := p.capture_aabb()  # where the particles are this frame, in the node's space
		if b.size == Vector3.ZERO:
			continue
		box = b if not found else box.merge(b)
		found = true
	if found:
		p.visibility_aabb = box.grow(margin)
	p.emitting = was_emitting
	return p.visibility_aabb

What we measured

A GPUParticles3D on the ground shooting 200 white sparks up at 12 to 14 m/s, 25 degree spread, light gravity, 2.5 s life. We counted the lit pixels on the rendered screen with the camera looking at the base, then looking up at the top of the fireworks with the base out of view. The sparks are random, so the counts differ a little between our two runs; the zeros were the same in both.

Why it happens

Before drawing, Godot skips everything whose box is outside the camera's view, which saves the work of drawing what cannot be seen. For a mesh the box comes from the mesh. Particles are simulated on the graphics card, so Godot cannot know in advance where they will go, and uses the fixed box you give it. Fireworks, tall fire, rain over a whole area or a wide explosion leave the default 8 m box quickly, and the effect disappears as soon as the box leaves the screen, even when the camera only turns a little.

What to change

Ready-made fireworks: Festival & Fireworks VFX for Godot 4 has rockets that burst by themselves, Peony, Willow Gold, Ring Cyan and more, plus fountains and sparklers.

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 and more, plus fountains and sparklers.

More how-tos for Festival & Fireworks VFX for Godot 4: Fireworks without sub-emitters · Confetti particles with random colors · Random directions spread evenly over a sphere or a cone

More how-tos: When particles do not show up