← Pixel Dreamer Studio

Confetti particles with random colors

A color ramp picks one color per piece. The material must use vertex color, or they are all white.

Give the process material a color_initial_ramp: each piece takes one random color from it when it is born. Set the gradient to Constant so it picks only your colors. Then turn on vertex_color_use_as_albedo in the material that draws the pieces: in our test, without it every lit point was white.

A burst of small paper pieces in red, yellow, green, blue and purple, some seen edge-on as they turn
The script below in Godot 4.7 with the Compatibility renderer, 1.4 seconds in.

The code

Attach this to a GPUParticles3D on a win screen and call restart(). The vertex_color_use_as_albedo line is the fix, and the ramp sets the colors.

extends GPUParticles3D
## A confetti burst for a win screen: flat paper pieces in five colors that spin and
## drift down. Call restart() to play it again.


func _ready() -> void:
	amount = 150
	lifetime = 4.0
	one_shot = true
	explosiveness = 1.0
	var colors := Gradient.new()
	colors.offsets = PackedFloat32Array([0.0, 0.2, 0.4, 0.6, 0.8])
	colors.colors = PackedColorArray([Color(1, 0.25, 0.3), Color(1, 0.8, 0.2), Color(0.3, 0.85, 0.4), Color(0.25, 0.6, 1), Color(0.8, 0.35, 1)])
	colors.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CONSTANT  # one of the five, no colors in between
	var ramp := GradientTexture1D.new()
	ramp.gradient = colors
	var m := ParticleProcessMaterial.new()
	m.color_initial_ramp = ramp  # one random color per piece
	m.direction = Vector3.UP
	m.spread = 35.0
	m.initial_velocity_min = 5.0
	m.initial_velocity_max = 7.0
	m.gravity = Vector3(0, -3, 0)
	m.damping_min = 2.0  # air: the pieces lose speed, so the burst stays lower. Keep it under the gravity or they stop falling.
	m.damping_max = 2.0
	m.particle_flag_rotate_y = true  # flat pieces that turn as they fall
	m.angle_max = 360.0
	m.angular_velocity_min = -300.0
	m.angular_velocity_max = 300.0
	process_material = m
	var mat := StandardMaterial3D.new()
	mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	mat.cull_mode = BaseMaterial3D.CULL_DISABLED  # paper has two sides
	mat.vertex_color_use_as_albedo = true  # the fix: without it every piece is white
	var q := QuadMesh.new()
	q.size = Vector2(0.12, 0.08)
	q.material = mat
	draw_pass_1 = q

What we measured

We used the same seed for every run, looked from the front with an orthographic camera, and sorted the lit pixels by color 1 second in. Two runs of each.

Keep damping under the gravity

damping takes speed off every piece all the time, like air, so the burst stays lower. Keep it below the gravity, 2 against 3 here. With damping larger than the gravity, particles stop falling and hang in the air, as we found with snow particles not falling.

What to change

Other ways vertex color matters: particle color ramp not working.

Tested in Godot 4.7 with the Compatibility renderer.

More how-tos: Game feel