How can I emit particles of different colors?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bashan

I have a 3D particles emitter emitting 20 white quads every second. How can I set the quads to be of multiple pre-selected colors?

:bust_in_silhouette: Reply From: SpkingR

You can set the color to the gradient in color param, or you can use 20 particles node to combine.

  • Tried the gradient, it is not the effect that I want: it colors the same quad in different colors during a single emission. I want each of the quads to have a different random color for the entire emission.
  • Adding 20 distinct particle nodes doesn’t sound like the right solution since obviously it doesn’t scale so well and I am using explosiveness of 0.5, so 20 distinct nodes lose the explosiveness effect, since each emitted node is not in sync with the rest of the nodes.

bashan | 2019-12-14 08:28

Oh, that’s it.
So you can use an animated sprite sheet as the particle material.
The sprite sheet contains different colored sprite, and while during the particle emission, the quad will be the sprite with random color.

SpkingR | 2019-12-14 09:28

I do not want to have a single particle changing its color in a single emission, but particles with multiple colors…

bashan | 2019-12-14 21:56

:bust_in_silhouette: Reply From: Xtremezero

When you create the material for the particles make sure to check (use as albedo in VERTEX_COLORS) in the material flags/attributes , then you can control the particles colors directly from the particle system settings

edit :
example video

I guess you mean under “Vertex Color” to check: “Use As Albedo” property. I already checked it. I do not see how that helps me to generate particles of different colors.

bashan | 2019-12-14 21:32

Here’s how to do it :
RandomColored Particles - Link to video

Xtremezero | 2019-12-15 02:11

That’s right, I even did not realize that there is the Hue Variation setting in particles material properties.
It also works in 2D, cool man.

SpkingR | 2019-12-16 09:27

:bust_in_silhouette: Reply From: SpkingR

Maybe you can give the particles shader a try, and I copy the code from other website, it works fine for the test scenario(I saw the different color though, haaa):

shader_type particles;

uniform int trail_divisor = 2;

float rand_from_seed(inout uint seed){
	int k;
	int s = int(seed);
	if(s == 0){
		s = 305420679;
		k = s / 127773;
		s = 16087 * (s - k * 127773) - 2836 * k;
	if(s < 0){
		s += 2147483647;
		seed = uint(s);
	return float(seed % uint(65536)) / 65535.0;

float rand_from_m1_p1(inout uint seed){
	return rand_from_seed(seed) * 2.0 - 1.0;

uint hash(uint x){
	x = ((x >> uint(16)) ^ x) * uint(73244475);
	x = ((x >> uint(16)) ^ x) * uint(73244475);
	x = (x >> uint(16)) ^ x;
	return x;

void vertex(){
	uint base_number = NUMBER / uint(trail_divisor);
	uint seed1 = hash(base_number + uint(1) + RANDOM_SEED);
	uint seed2 = hash(base_number + uint(2) + RANDOM_SEED);
	float rand1 = rand_from_m1_p1(seed1);
	float rand2 = rand_from_m1_p1(seed2);
	VELOCITY = vec3(100.0 * rand1, 100.0 * rand2, 0.0);
	COLOR = vec4(fract(rand1), fract(rand2), sin(TIME), 1.0);

Create a ShaderMatierial for your Particles2D node, add new shader script and copy-paste to it, plz try with a different value of paramters.
Hope this helps.

After try and modify the code, the particles seem more random and colorful:

uniform int trail_divisor = 1;
uniform float scale = 5;

then in the vertex function add the code:

TRANSFORM[0][0] = scale;
TRANSFORM[1][1] = scale;

SpkingR | 2019-12-15 04:51