2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #define MAX_PARTICLES 2048 // default max # of particles at one
25 #define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's
26 // on the command line
28 int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
29 int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
30 int ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
33 int smokeparticletexture;
34 int flareparticletexture;
35 int rainparticletexture;
36 int bloodcloudparticletexture;
37 int bubbleparticletexture;
39 particle_t *active_particles, *free_particles;
41 particle_t *particles;
44 vec3_t r_pright, r_pup, r_ppn;
46 //extern cvar_t r_particles/*, r_smoke*/, r_smokealpha;
47 //cvar_t r_smokecolor = {"r_smokecolor", "0"};
49 void fractalnoise(char *noise, int size);
50 void fractalnoise_zeroedge(char *noise, int size);
52 void R_InitParticleTexture (void)
55 float dx, dy, dz, f, dot;
56 byte data[64][64][4], noise1[64][64], noise2[64][64];
59 particletexture = texture_extension_number++;
60 glBindTexture(GL_TEXTURE_2D, particletexture);
62 for (x=0 ; x<64 ; x++)
64 for (y=0 ; y<64 ; y++)
66 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
69 d = (255 - (dx*dx+dy*dy));
71 data[y][x][3] = (byte) d;
74 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
76 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
78 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
79 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
82 fractalnoise(&noise1[0][0], 64);
83 fractalnoise(&noise2[0][0], 64);
84 for (y = 0;y < 64;y++)
85 for (x = 0;x < 64;x++)
87 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
90 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
93 data[y][x][3] = (byte) d;
97 for (x=0 ; x<34 ; x+=2)
98 for (y=0 ; y<34 ; y+=2)
99 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%64)+192;
100 for (x=0 ; x<32 ; x+=2)
101 for (y=0 ; y<32 ; y+=2)
103 data[y ][x+1][0] = data[y ][x+1][1] = data[y ][x+1][2] = (int) (data[y ][x ][0] + data[y ][x+2][0]) >> 1;
104 data[y+1][x ][0] = data[y+1][x ][1] = data[y+1][x ][2] = (int) (data[y ][x ][0] + data[y+2][x ][0]) >> 1;
105 data[y+1][x+1][0] = data[y+1][x+1][1] = data[y+1][x+1][2] = (int) (data[y ][x ][0] + data[y ][x+2][0] + data[y+2][x ][0] + data[y+2][x+2][0]) >> 2;
107 for (x=0 ; x<64 ; x++)
109 for (y=0 ; y<64 ; y++)
111 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+64;
114 d = (255 - (dx*dx+dy*dy));
116 data[y][x][3] = (byte) d;
120 smokeparticletexture = texture_extension_number++;
121 glBindTexture(GL_TEXTURE_2D, smokeparticletexture);
122 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
123 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
124 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
125 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
127 fractalnoise(&noise1[0][0], 64);
128 fractalnoise(&noise2[0][0], 64);
129 for (y = 0;y < 64;y++)
130 for (x = 0;x < 64;x++)
132 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
135 d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
137 if (d > 255) d = 255;
138 data[y][x][3] = (byte) d;
141 bloodcloudparticletexture = texture_extension_number++;
142 glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
143 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
144 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
145 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
146 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
148 flareparticletexture = texture_extension_number++;
149 glBindTexture(GL_TEXTURE_2D, flareparticletexture);
151 for (x=0 ; x<64 ; x++)
153 for (y=0 ; y<64 ; y++)
155 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
158 d = 2048 / (dx*dx+dy*dy+1) - 32;
159 d = bound(0, d, 255);
160 data[y][x][3] = (byte) d;
163 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
165 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
167 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
168 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
170 rainparticletexture = texture_extension_number++;
171 glBindTexture(GL_TEXTURE_2D, rainparticletexture);
173 for (x=0 ; x<64 ; x++)
175 for (y=0 ; y<64 ; y++)
177 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
178 if (y < 24) // stretch the upper half to make a raindrop
182 d = (255 - (dx*dx+dy*dy))/2;
188 d = (255 - (dx*dx+dy*dy))/2;
191 data[y][x][3] = (byte) d;
194 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
196 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
198 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
199 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
201 bubbleparticletexture = texture_extension_number++;
202 glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
204 light[0] = 1;light[1] = 1;light[2] = 1;
205 VectorNormalize(light);
206 for (x=0 ; x<64 ; x++)
208 for (y=0 ; y<64 ; y++)
210 data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
211 dx = x * (1.0 / 16.0) - 1.0;
212 dy = y * (1.0 / 16.0) - 1.0;
213 if (dx*dx+dy*dy < 1) // it does hit the sphere
215 dz = 1 - (dx*dx+dy*dy);
218 normal[0] = dx;normal[1] = dy;normal[2] = dz;
219 VectorNormalize(normal);
220 dot = DotProduct(normal, light);
221 if (dot > 0.5) // interior reflection
222 f += ((dot * 2) - 1);
223 else if (dot < -0.5) // exterior reflection
224 f += ((dot * -2) - 1);
226 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
227 VectorNormalize(normal);
228 dot = DotProduct(normal, light);
229 if (dot > 0.5) // interior reflection
230 f += ((dot * 2) - 1);
231 else if (dot < -0.5) // exterior reflection
232 f += ((dot * -2) - 1);
234 f = bound(0, f, 255);
235 data[y][x][3] = (byte) d;
241 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
243 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
245 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
246 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
254 void R_InitParticles (void)
258 i = COM_CheckParm ("-particles");
262 r_numparticles = (int)(atoi(com_argv[i+1]));
263 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
264 r_numparticles = ABSOLUTE_MIN_PARTICLES;
268 r_numparticles = MAX_PARTICLES;
271 particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
273 // Cvar_RegisterVariable (&r_smokecolor);
274 R_InitParticleTexture ();
283 #define NUMVERTEXNORMALS 162
284 extern float r_avertexnormals[NUMVERTEXNORMALS][3];
285 vec3_t avelocities[NUMVERTEXNORMALS];
286 float beamlength = 16;
287 vec3_t avelocity = {23, 7, 3};
288 float partstep = 0.01;
289 float timescale = 0.01;
291 void R_EntityParticles (entity_t *ent)
297 float sr, sp, sy, cr, cp, cy;
300 // if (!r_particles.value) return; // LordHavoc: particles are optional
305 if (!avelocities[0][0])
307 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
308 avelocities[0][i] = (rand()&255) * 0.01;
312 for (i=0 ; i<NUMVERTEXNORMALS ; i++)
314 angle = cl.time * avelocities[i][0];
317 angle = cl.time * avelocities[i][1];
320 angle = cl.time * avelocities[i][2];
331 free_particles = p->next;
332 p->next = active_particles;
333 active_particles = p;
335 p->texnum = flareparticletexture;
338 p->die = cl.time + 0.01;
340 p->type = pt_explode;
342 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
343 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
344 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
354 void R_ClearParticles (void)
358 free_particles = &particles[0];
359 active_particles = NULL;
361 for (i=0 ;i<r_numparticles ; i++)
362 particles[i].next = &particles[i+1];
363 particles[r_numparticles-1].next = NULL;
367 void R_ReadPointFile_f (void)
374 char name[MAX_OSPATH];
376 sprintf (name,"maps/%s.pts", sv.name);
378 COM_FOpenFile (name, &f, false);
381 Con_Printf ("couldn't open %s\n", name);
385 Con_Printf ("Reading %s...\n", name);
389 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
396 Con_Printf ("Not enough free particles\n");
400 free_particles = p->next;
401 p->next = active_particles;
402 active_particles = p;
404 p->texnum = particletexture;
410 VectorCopy (vec3_origin, p->vel);
411 VectorCopy (org, p->org);
415 Con_Printf ("%i points read\n", c);
420 R_ParseParticleEffect
422 Parse an effect out of the server message
425 void R_ParseParticleEffect (void)
428 int i, count, msgcount, color;
430 for (i=0 ; i<3 ; i++)
431 org[i] = MSG_ReadCoord ();
432 for (i=0 ; i<3 ; i++)
433 dir[i] = MSG_ReadChar () * (1.0/16);
434 msgcount = MSG_ReadByte ();
435 color = MSG_ReadByte ();
442 R_RunParticleEffect (org, dir, color, count);
451 void R_ParticleExplosion (vec3_t org, int smoke)
455 // if (!r_particles.value) return; // LordHavoc: particles are optional
457 for (i=0 ; i<1024 ; i++)
462 free_particles = p->next;
463 p->next = active_particles;
464 active_particles = p;
466 p->texnum = flareparticletexture;
467 p->scale = 4+(rand()&7);
468 p->alpha = rand()&255;
469 p->die = cl.time + 5;
474 p->type = pt_explode;
476 p->type = pt_explode2;
478 p->color = ramp1[rand()&7];
479 p->type = pt_fallfadespark;
480 for (j=0 ; j<3 ; j++)
482 p->org[j] = org[j] + ((rand()&63)-32);
483 p->vel[j] = (rand()&511)-256;
490 for (i=0 ; i<32 ; i++)
495 free_particles = p->next;
496 p->next = active_particles;
497 active_particles = p;
499 p->texnum = smokeparticletexture;
502 p->die = cl.time + 2;
504 p->color = (rand()&7) + 8;
505 for (j=0 ; j<3 ; j++)
507 p->org[j] = org[j] + ((rand()%96)-48);
508 p->vel[j] = (rand()&63)-32;
520 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
525 // if (!r_particles.value) return; // LordHavoc: particles are optional
527 for (i=0; i<512; i++)
532 free_particles = p->next;
533 p->next = active_particles;
534 active_particles = p;
536 p->texnum = flareparticletexture;
539 p->die = cl.time + 0.3;
540 p->color = colorStart + (colorMod % colorLength);
544 for (j=0 ; j<3 ; j++)
546 p->org[j] = org[j] + ((rand()%32)-16);
547 p->vel[j] = (rand()%512)-256;
558 void R_BlobExplosion (vec3_t org)
562 // if (!r_particles.value) return; // LordHavoc: particles are optional
564 for (i=0 ; i<1024 ; i++)
569 free_particles = p->next;
570 p->next = active_particles;
571 active_particles = p;
573 p->texnum = flareparticletexture;
576 p->die = cl.time + 1 + (rand()&8)*0.05;
581 p->color = 66 + rand()%6;
582 for (j=0 ; j<3 ; j++)
584 p->org[j] = org[j] + ((rand()%32)-16);
585 p->vel[j] = (rand()%512)-256;
591 p->color = 150 + rand()%6;
592 for (j=0 ; j<3 ; j++)
594 p->org[j] = org[j] + ((rand()%32)-16);
595 p->vel[j] = (rand()%512)-256;
607 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
611 // if (!r_particles.value) return; // LordHavoc: particles are optional
613 for (i=0 ; i<count ; i++)
618 free_particles = p->next;
619 p->next = active_particles;
620 active_particles = p;
623 { // rocket explosion
624 p->texnum = flareparticletexture;
627 p->die = cl.time + 5;
632 p->type = pt_explode;
633 for (j=0 ; j<3 ; j++)
635 p->org[j] = org[j] + ((rand()%32)-16);
636 p->vel[j] = (rand()%512)-256;
641 p->type = pt_explode2;
642 for (j=0 ; j<3 ; j++)
644 p->org[j] = org[j] + ((rand()%32)-16);
645 p->vel[j] = (rand()%512)-256;
651 p->texnum = flareparticletexture;
654 p->die = cl.time + 0.1*(rand()%5);
655 p->color = (color&~7) + (rand()&7);
656 p->type = pt_static; //slowgrav;
657 for (j=0 ; j<3 ; j++)
659 p->org[j] = org[j] + ((rand()&15)-8);
660 p->vel[j] = dir[j]*15;// + (rand()%300)-150;
666 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
673 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
677 // if (!r_particles.value) return; // LordHavoc: particles are optional
682 free_particles = p->next;
683 p->next = active_particles;
684 active_particles = p;
685 if (type == 0) // sparks
687 p->texnum = smokeparticletexture;
690 p->color = (rand()&3)+12;
691 p->type = pt_bulletpuff;
692 p->die = cl.time + 1;
693 VectorCopy(org, p->org);
694 p->vel[0] = p->vel[1] = p->vel[2] = 0;
698 p->texnum = bloodcloudparticletexture;
701 p->color = (rand()&3)+68;
702 p->type = pt_bloodcloud;
703 p->die = cl.time + 0.5;
704 VectorCopy(org, p->org);
705 p->vel[0] = p->vel[1] = p->vel[2] = 0;
708 for (i=0 ; i<count ; i++)
713 free_particles = p->next;
714 p->next = active_particles;
715 active_particles = p;
717 p->texnum = flareparticletexture;
720 p->die = cl.time + 0.0625 * (rand()&15);
722 if (type == 0) // sparks
726 p->ramp = (rand()&3);
727 p->color = ramp1[(int)p->ramp];
728 for (j=0 ; j<3 ; j++)
730 p->org[j] = org[j] + ((rand()&7)-4);
731 p->vel[j] = dir[j] + (rand()%192)-96;
737 p->type = pt_fadespark2;
738 p->color = 67 + (rand()&3);
739 for (j=0 ; j<3 ; j++)
741 p->org[j] = org[j] + (rand()&7)-4;
742 p->vel[j] = dir[j] + (rand()&63)-32;
749 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
756 // if (!r_particles.value) return; // LordHavoc: particles are optional
758 VectorSubtract(maxs, mins, diff);
759 center[0] = (mins[0] + maxs[0]) * 0.5;
760 center[1] = (mins[1] + maxs[1]) * 0.5;
761 center[2] = (mins[2] + maxs[2]) * 0.5;
762 velscale[0] = velspeed * 2.0 / diff[0];
763 velscale[1] = velspeed * 2.0 / diff[1];
764 velscale[2] = velspeed * 2.0 / diff[2];
766 for (i=0 ; i<count ; i++)
771 free_particles = p->next;
772 p->next = active_particles;
773 active_particles = p;
775 p->texnum = bloodcloudparticletexture;
777 p->alpha = 96 + (rand()&63);
778 p->die = cl.time + 2; //0.015625 * (rand()%128);
779 p->type = pt_fadespark;
780 p->color = (rand()&3)+68;
781 // p->color = 67 + (rand()&3);
782 for (j=0 ; j<3 ; j++)
784 p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
785 p->vel[j] = (p->org[j] - center[j]) * velscale[j];
790 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
796 // if (!r_particles.value) return; // LordHavoc: particles are optional
797 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
798 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
799 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
801 VectorSubtract(maxs, mins, diff);
803 for (i=0 ; i<count ; i++)
808 free_particles = p->next;
809 p->next = active_particles;
810 active_particles = p;
812 p->texnum = flareparticletexture;
815 p->die = cl.time + 1 + (rand()&15)*0.0625;
820 p->color = colorbase + (rand()&3);
821 for (j=0 ; j<3 ; j++)
823 p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
825 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
832 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
840 // if (!r_particles.value) return; // LordHavoc: particles are optional
841 if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
842 if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
843 if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
844 if (dir[2] < 0) // falling
846 t = (maxs[2] - mins[2]) / -dir[2];
851 t = (maxs[2] - mins[2]) / dir[2];
854 if (t < 0 || t > 2) // sanity check
858 VectorSubtract(maxs, mins, diff);
860 for (i=0 ; i<count ; i++)
865 free_particles = p->next;
866 p->next = active_particles;
867 active_particles = p;
869 vel[0] = dir[0] + (rand()&31) - 16;
870 vel[1] = dir[1] + (rand()&31) - 16;
871 vel[2] = dir[2] + (rand()&63) - 32;
872 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
873 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
881 p->texnum = particletexture;
886 p->texnum = rainparticletexture;
889 p->color = colorbase + (rand()&3);
890 VectorCopy(org, p->org);
891 VectorCopy(vel, p->vel);
902 void R_LavaSplash (vec3_t org)
908 // if (!r_particles.value) return; // LordHavoc: particles are optional
910 for (i=-16 ; i<16 ; i+=2)
911 for (j=-16 ; j<16 ; j+=2)
912 for (k=0 ; k<1 ; k++)
917 free_particles = p->next;
918 p->next = active_particles;
919 active_particles = p;
921 p->texnum = flareparticletexture;
924 p->die = cl.time + 2 + (rand()&31) * 0.02;
925 p->color = 224 + (rand()&7);
926 p->type = pt_slowgrav;
928 dir[0] = j*8 + (rand()&7);
929 dir[1] = i*8 + (rand()&7);
932 p->org[0] = org[0] + dir[0];
933 p->org[1] = org[1] + dir[1];
934 p->org[2] = org[2] + (rand()&63);
936 VectorNormalize (dir);
937 vel = 50 + (rand()&63);
938 VectorScale (dir, vel, p->vel);
948 void R_TeleportSplash (vec3_t org)
953 // if (!r_particles.value) return; // LordHavoc: particles are optional
956 for (i=-16 ; i<16 ; i+=4)
957 for (j=-16 ; j<16 ; j+=4)
958 for (k=-24 ; k<32 ; k+=4)
963 free_particles = p->next;
964 p->next = active_particles;
965 active_particles = p;
967 p->texnum = particletexture;
970 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
971 p->color = 7 + (rand()&7);
972 p->type = pt_slowgrav;
978 p->org[0] = org[0] + i + (rand()&3);
979 p->org[1] = org[1] + j + (rand()&3);
980 p->org[2] = org[2] + k + (rand()&3);
982 VectorNormalize (dir);
983 vel = 50 + (rand()&63);
984 VectorScale (dir, vel, p->vel);
988 for (i=-24 ; i<24 ; i+=8)
989 for (j=-24 ; j<24 ; j+=8)
990 for (k=-24 ; k<32 ; k+=8)
995 free_particles = p->next;
996 p->next = active_particles;
997 active_particles = p;
999 p->texnum = flareparticletexture;
1001 p->alpha = (1 + rand()&7) * 32;
1002 p->die = cl.time + 5;
1003 p->color = 254; //8 + (rand()&7);
1004 p->type = pt_fadespark;
1006 p->org[0] = org[0] + i + (rand()&7);
1007 p->org[1] = org[1] + j + (rand()&7);
1008 p->org[2] = org[2] + k + (rand()&7);
1010 p->vel[0] = i*2 + (rand()%25) - 12;
1011 p->vel[1] = j*2 + (rand()%25) - 12;
1012 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
1016 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
1019 float len, dec, t, nt, speed;
1020 int j, contents, bubbles;
1022 static int tracercount;
1023 // if (!r_particles.value) return; // LordHavoc: particles are optional
1027 if (ent->trail_leftover < 0)
1028 ent->trail_leftover = 0;
1029 t += ent->trail_leftover;
1030 ent->trail_leftover -= (cl.time - cl.oldtime);
1034 contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1035 if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1038 VectorSubtract (end, start, vec);
1039 len = VectorNormalizeLength (vec);
1042 speed = len / (nt - t);
1044 bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1048 if (!free_particles)
1051 free_particles = p->next;
1052 p->next = active_particles;
1053 active_particles = p;
1055 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1056 p->die = cl.time + 2;
1060 case 0: // rocket trail
1061 case 1: // grenade trail
1065 p->texnum = bubbleparticletexture;
1066 p->scale = 6+(rand()&3);
1068 // if (r_smokecolor.value)
1069 // p->color = r_smokecolor.value;
1071 p->color = (rand()&3)+12;
1072 p->type = pt_bubble;
1073 p->die = cl.time + 2;
1074 for (j=0 ; j<3 ; j++)
1076 p->vel[j] = (rand()&31)-16;
1077 p->org[j] = start[j] + ((rand()&3)-2);
1083 p->texnum = smokeparticletexture;
1084 p->scale = 12+(rand()&7);
1085 p->alpha = 64 + (rand()&31);
1086 // if (r_smokecolor.value)
1087 // p->color = r_smokecolor.value;
1089 p->color = (rand()&3)+12;
1091 p->die = cl.time + 2;
1092 VectorCopy(start, p->org);
1097 case 1: // smoke smoke
1099 p->texnum = smokeparticletexture;
1100 p->scale = 12+rand()&7;
1102 if (r_smokecolor.value)
1103 p->color = r_smokecolor.value;
1105 p->color = (rand()&3)+12;
1107 p->die = cl.time + 1;
1108 VectorCopy(start, p->org);
1114 p->texnum = bloodcloudparticletexture;
1115 p->scale = 20+(rand()&7);
1117 p->color = (rand()&3)+68;
1118 p->type = pt_bloodcloud;
1119 p->die = cl.time + 2;
1120 for (j=0 ; j<3 ; j++)
1122 p->vel[j] = (rand()&15)-8;
1123 p->org[j] = start[j] + ((rand()&3)-2);
1130 p->texnum = flareparticletexture;
1133 p->die = cl.time + 0.2; //5;
1134 p->type = pt_static;
1136 p->color = 52 + ((tracercount&4)<<1);
1138 p->color = 230 + ((tracercount&4)<<1);
1142 VectorCopy (start, p->org);
1143 if (tracercount & 1)
1145 p->vel[0] = 30*vec[1];
1146 p->vel[1] = 30*-vec[0];
1150 p->vel[0] = 30*-vec[1];
1151 p->vel[1] = 30*vec[0];
1155 case 4: // slight blood
1156 dec = 0.03f; // sparse trail
1157 p->texnum = bloodcloudparticletexture;
1158 p->scale = 20+(rand()&7);
1160 p->color = (rand()&3)+68;
1161 p->type = pt_fadespark2;
1162 p->die = cl.time + 2;
1163 for (j=0 ; j<3 ; j++)
1165 p->vel[j] = (rand()&15)-8;
1166 p->org[j] = start[j] + ((rand()&3)-2);
1170 case 6: // voor trail
1171 dec = 0.05f; // sparse trail
1172 p->texnum = flareparticletexture;
1173 p->scale = 20+(rand()&7);
1175 p->color = 9*16 + 8 + (rand()&3);
1176 p->type = pt_fadespark2;
1177 p->die = cl.time + 2;
1178 for (j=0 ; j<3 ; j++)
1180 p->vel[j] = (rand()&15)-8;
1181 p->org[j] = start[j] + ((rand()&3)-2);
1185 case 7: // Nehahra smoke tracer
1187 p->texnum = smokeparticletexture;
1188 p->scale = 12+(rand()&7);
1190 p->color = (rand()&3)+12;
1192 p->die = cl.time + 1;
1193 for (j=0 ; j<3 ; j++)
1194 p->org[j] = start[j] + ((rand()&3)-2);
1200 VectorMA (start, dec, vec, start);
1202 ent->trail_leftover = t - cl.time;
1205 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1210 static int tracercount;
1211 // if (!r_particles.value) return; // LordHavoc: particles are optional
1213 VectorSubtract (end, start, vec);
1214 len = VectorNormalizeLength (vec);
1219 if (!free_particles)
1222 free_particles = p->next;
1223 p->next = active_particles;
1224 active_particles = p;
1226 VectorCopy (vec3_origin, p->vel);
1228 p->texnum = flareparticletexture;
1233 p->die = cl.time + 1;
1234 VectorCopy(start, p->org);
1235 // for (j=0 ; j<3 ; j++)
1236 // p->org[j] = start[j] + ((rand()&15)-8);
1238 VectorAdd (start, vec, start);
1243 //extern qboolean isG200, isATI, isRagePro;
1244 extern qboolean lighthalf;
1251 extern cvar_t sv_gravity;
1253 void R_DrawParticles (void)
1255 particle_t *p, *kill;
1256 int i, /*texnum, */r,g,b,a;
1257 float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2;
1259 vec3_t up, right, uprightangles, forward2, up2, right2, v;
1261 // LordHavoc: early out condition
1262 if (!active_particles)
1266 texnum = particletexture;
1267 glBindTexture(GL_TEXTURE_2D, texnum);
1268 glEnable (GL_BLEND);
1269 // LordHavoc: Matrox G200 cards can't handle per pixel alpha at all...
1270 // and ATI Rage Pro can't modulate a per pixel alpha texture
1271 if (isG200 || isRagePro)
1272 glEnable(GL_ALPHA_TEST);
1274 glDisable(GL_ALPHA_TEST);
1275 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1276 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1277 glDepthMask(0); // disable zbuffer updates
1278 glShadeModel(GL_FLAT);
1279 glBegin (GL_TRIANGLES);
1282 VectorScale (vup, 1.5, up);
1283 VectorScale (vright, 1.5, right);
1285 uprightangles[0] = 0;
1286 uprightangles[1] = r_refdef.viewangles[1];
1287 uprightangles[2] = 0;
1288 AngleVectors (uprightangles, forward2, right2, up2);
1290 frametime = cl.time - cl.oldtime;
1291 time3 = frametime * 15;
1292 time2 = frametime * 10; // 15;
1293 time1 = frametime * 5;
1294 grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1295 dvel = 1+4*frametime;
1299 kill = active_particles;
1300 if (kill && kill->die < cl.time)
1302 active_particles = kill->next;
1303 kill->next = free_particles;
1304 free_particles = kill;
1310 for (p=active_particles ; p ; p=p->next)
1315 if (kill && kill->die < cl.time)
1317 p->next = kill->next;
1318 kill->next = free_particles;
1319 free_particles = kill;
1324 // LordHavoc: 'removed last in list' condition
1328 VectorSubtract(p->org, r_refdef.vieworg, v);
1329 if (DotProduct(v, v) >= 256.0f)
1331 scale = p->scale * -0.25;scale2 = p->scale * 0.75;
1333 if (p->texnum != texnum)
1337 glBindTexture(GL_TEXTURE_2D, texnum);
1338 glBegin(GL_TRIANGLES);
1342 color24 = (byte *)&d_8to24table[(int)p->color];
1343 if (p->texnum == smokeparticletexture)
1344 glColor4ub((byte) (color24[0] >> 1), (byte) (color24[1] >> 1), (byte) (color24[2] >> 1), (byte) (p->alpha*r_smokealpha.value));
1346 glColor4ub((byte) (color24[0] >> 1), (byte) (color24[1] >> 1), (byte) (color24[2] >> 1), (byte) p->alpha);
1350 color24 = (byte *) &d_8to24table[(int)p->color];
1351 if (p->texnum == smokeparticletexture)
1352 glColor4ub(color24[0], color24[1], color24[2], (byte) (p->alpha*r_smokealpha.value));
1354 glColor4ub(color24[0], color24[1], color24[2], (byte) p->alpha);
1356 if (p->texnum == rainparticletexture) // rain streak
1359 glVertex3f (p->org[0] + right2[0]*scale , p->org[1] + right2[1]*scale , p->org[2] + right2[2]*scale );
1361 glVertex3f (p->org[0] + right2[0]*scale , p->org[1] + right2[1]*scale , p->org[2] + right2[2]*scale );
1363 glVertex3f (p->org[0] + right2[0]*scale2, p->org[1] + right2[1]*scale2, p->org[2] + right2[2]*scale2);
1368 // LordHavoc: centered particle sprites
1369 glVertex3f (p->org[0] + up[0]*scale + right[0]*scale , p->org[1] + up[1]*scale + right[1]*scale , p->org[2] + up[2]*scale + right[2]*scale );
1371 glVertex3f (p->org[0] + up[0]*scale2 + right[0]*scale , p->org[1] + up[1]*scale2 + right[1]*scale , p->org[2] + up[2]*scale2 + right[2]*scale );
1373 glVertex3f (p->org[0] + up[0]*scale + right[0]*scale2, p->org[1] + up[1]*scale + right[1]*scale2, p->org[2] + up[2]*scale + right[2]*scale2);
1376 color24 = (byte *) &d_8to24table[(int)p->color];
1387 transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1388 if (p->texnum == rainparticletexture) // rain streak
1390 transpolyvert(p->org[0] + right2[0]*scale , p->org[1] + right2[1]*scale , p->org[2] + right2[2]*scale , 0,0,r,g,b,a);
1391 transpolyvert(p->org[0] + right2[0]*scale , p->org[1] + right2[1]*scale , p->org[2] + right2[2]*scale , 1,0,r,g,b,a);
1392 transpolyvert(p->org[0] + right2[0]*scale2, p->org[1] + right2[1]*scale2, p->org[2] + right2[2]*scale2, 0,1,r,g,b,a);
1396 transpolyvert(p->org[0] + up[0]*scale + right[0]*scale , p->org[1] + up[1]*scale + right[1]*scale , p->org[2] + up[2]*scale + right[2]*scale , 0,0,r,g,b,a);
1397 transpolyvert(p->org[0] + up[0]*scale2 + right[0]*scale , p->org[1] + up[1]*scale2 + right[1]*scale , p->org[2] + up[2]*scale2 + right[2]*scale , 1,0,r,g,b,a);
1398 transpolyvert(p->org[0] + up[0]*scale + right[0]*scale2, p->org[1] + up[1]*scale + right[1]*scale2, p->org[2] + up[2]*scale + right[2]*scale2, 0,1,r,g,b,a);
1403 p->org[0] += p->vel[0]*frametime;
1404 p->org[1] += p->vel[1]*frametime;
1405 p->org[2] += p->vel[2]*frametime;
1416 p->color = ramp3[(int)p->ramp];
1425 p->color = ramp1[(int)p->ramp];
1426 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1427 for (i=0 ; i<3 ; i++)
1429 // p->vel[2] -= grav;
1437 p->color = ramp2[(int)p->ramp];
1438 // p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1439 for (i=0 ; i<3 ; i++)
1440 p->vel[i] -= p->vel[i]*frametime;
1441 // p->vel[2] -= grav;
1445 for (i=0 ; i<3 ; i++)
1446 p->vel[i] += p->vel[i]*dvel;
1451 for (i=0 ; i<2 ; i++)
1452 p->vel[i] -= p->vel[i]*dvel;
1462 // LordHavoc: gunshot spark showers
1465 p->scale -= frametime * 4;
1466 if (p->ramp >= 8 || p->scale <= 0)
1469 p->color = ramp3[(int)p->ramp];
1472 // LordHavoc: for smoke trails
1474 p->scale += frametime * 16;
1475 p->alpha -= frametime * 64;
1481 if (cl.time > p->time2)
1483 p->time2 = cl.time + 0.4;
1484 p->vel[0] = (rand()&63)-32;
1485 p->vel[1] = (rand()&63)-32;
1489 p->scale -= frametime * 64;
1490 p->alpha -= frametime * 1024;
1492 if (p->alpha < 1 || p->scale < 1)
1496 p->scale -= frametime * 24;
1497 p->alpha -= frametime * 128;
1499 if (p->alpha < 1 || p->scale < 1)
1503 p->alpha -= frametime * 256;
1509 p->alpha -= frametime * 512;
1514 case pt_fallfadespark:
1515 p->alpha -= frametime * 256;
1520 case pt_fallfadespark2:
1521 p->alpha -= frametime * 512;
1528 if (p->vel[2] >= 100)
1529 p->vel[2] = 68+rand()&31;
1530 if (cl.time > p->time2)
1532 p->time2 = cl.time + (rand()&7)*0.0625;
1533 p->vel[0] = (rand()&63)-32;
1534 p->vel[1] = (rand()&63)-32;
1536 p->alpha -= frametime * 32;
1545 glShadeModel(GL_SMOOTH);
1546 glDepthMask(1); // enable zbuffer updates
1547 glDisable (GL_BLEND);