0 votes

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?

asked Dec 13, 2019 in Engine by bashan (47 points)

3 Answers

0 votes

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

answered Dec 14, 2019 by SpkingR (126 points)
  • 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.

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.

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

+1 vote

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

answered Dec 14, 2019 by Xtremezero (288 points)
edited Dec 16, 2019 by Xtremezero

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.

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.

0 votes

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.

answered Dec 15, 2019 by SpkingR (126 points)

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;
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.