Posted By: 3run
sorting of translucent particles - 04/11/15 16:49
I'm having sorting problems with particles (non translucent vs translucent), and would like to know where do I dig? I've read in the manual that I could give a non transparent overlay bmap for particles, does it mean that sorting issue can be solved by having an image with alpha channel? It did not help me anyway, I use simple white .png image, and I change its color to get different particle effects (masterQ32 thank you for the idea ). I tried to use white .tga with same size and white alpha channel, didn't help. I don't want to use sprites in order to solve this sorting issue, maybe there is another way I'm missing?
Best regards
edit: additional question is about framerate independence for spawning particles, how does engine create/spawn particles? in the manual there is an example how to spawn particles independent to framerate (maxv(1, 40 * time_step). At first I thought it will set amount of spawning particles to a fixed value, independent to framerate, but it just adjusts value of spawning particles to keep it more or less the same.
Just run it, press ENTER and you'll see how how the number of particles goes up.
Best regards
edit: additional question is about framerate independence for spawning particles, how does engine create/spawn particles? in the manual there is an example how to spawn particles independent to framerate (maxv(1, 40 * time_step). At first I thought it will set amount of spawning particles to a fixed value, independent to framerate, but it just adjusts value of spawning particles to keep it more or less the same.
Originally Posted By: 3run
Quote:
For keeping the particle number independent of the frame rate on continuous particle generation, multiply the number of generated particles with time_step (see example).
Just run it, press ENTER and you'll see how how the number of particles goes up.
Code:
// fade smoke away: function fadeSmokeTrailPar(PARTICLE* p){ // decrease alpha: p.alpha -= p.skill_x * time_step; // if we don't have alpha, kill particle: if(p.alpha <= 0){ p.lifespan = 0; } } // smoke trail particle: function smokeTrailPar(PARTICLE* p){ // set color to white: vec_set(p.blue, COLOR_GREY); // set size: p.size = 4; // set gravity: p.gravity = -0.4; // set alpha: p.alpha = 30; // set fading speed: p.skill_x = 1; // set flags: set(p, MOVE | BRIGHT | BEAM | TRANSLUCENT); // set event: p.event = fadeSmokeTrailPar; } // main function: void main(){ // set framerate limit: fps_max = 500; // empty level: level_load(""); // wait 3 frames: wait(3); // set camera positions/angles: vec_set(camera.x, vector(-140, 0, 90)); vec_set(camera.pan, vector(0, -13, 0)); // vectors: VECTOR vectexVec; // reset vectors: vec_fill(vectexVec.x, 0); // create smoke emmiter: ENTITY* smokeEnt = ent_create(CUBE_MDL, vector(200, 0, 0), NULL); // scale it down: vec_fill(smokeEnt.scale_x, 0.35); // set it's flags: set(smokeEnt, PASSABLE | TRANSLUCENT); // save position: vec_set(smokeEnt.skill1, smokeEnt.x); // loop: while(1){ // reset framerate limit: fps_max = 500; // if ENTER is pressed: if(key_enter){ // decrease framerate limit: fps_max = 60; } // show framerate: DEBUG_VAR(fps_max, 30); DEBUG_VAR(num_particles, 50); // show text: draw_text("PRESS <ENTER> TO LOWER FRAMERATE!", 10, 10, COLOR_WHITE); // rotate smoke emitter: smokeEnt.pan = cycle(smokeEnt.pan + 30 * time_step, 0, 360); // move it: smokeEnt.z = smokeEnt.skill3 + fsin(total_ticks * 8, 64); smokeEnt.y = smokeEnt.skill2 + fcos(total_ticks * 8, 64); // get position of upper left vertex: vec_for_vertex(vectexVec.x, smokeEnt, 3); // create smoke trail with particles: effect(smokeTrailPar, maxv(1, 40 * time_step), vectexVec.x, nullvector); // wait one frame: wait(1); } }