#include "image.h"
#include "r_shadow.h"
-#define ABSOLUTE_MAX_PARTICLES 1<<24 // upper limit on cl.max_particles
-#define ABSOLUTE_MAX_DECALS 1<<24 // upper limit on cl.max_decals
-
// must match ptype_t values
particletype_t particletype[pt_total] =
{
cvar_t cl_particles_size = {CVAR_SAVE, "cl_particles_size", "1", "multiplies particle size"};
cvar_t cl_particles_quake = {CVAR_SAVE, "cl_particles_quake", "0", "makes particle effects look mostly like the ones in Quake"};
cvar_t cl_particles_blood = {CVAR_SAVE, "cl_particles_blood", "1", "enables blood effects"};
-cvar_t cl_particles_blood_alpha = {CVAR_SAVE, "cl_particles_blood_alpha", "1", "opacity of blood"};
+cvar_t cl_particles_blood_alpha = {CVAR_SAVE, "cl_particles_blood_alpha", "1", "opacity of blood, does not affect decals"};
+cvar_t cl_particles_blood_decal_alpha = {CVAR_SAVE, "cl_particles_blood_decal_alpha", "1", "opacity of blood decal"};
+cvar_t cl_particles_blood_decal_scalemin = {CVAR_SAVE, "cl_particles_blood_decal_scalemin", "1.5", "minimal random scale of decal"};
+cvar_t cl_particles_blood_decal_scalemax = {CVAR_SAVE, "cl_particles_blood_decal_scalemax", "2", "maximal random scale of decal"};
cvar_t cl_particles_blood_bloodhack = {CVAR_SAVE, "cl_particles_blood_bloodhack", "1", "make certain quake particle() calls create blood effects instead"};
cvar_t cl_particles_bulletimpacts = {CVAR_SAVE, "cl_particles_bulletimpacts", "1", "enables bulletimpact effects"};
cvar_t cl_particles_explosions_sparks = {CVAR_SAVE, "cl_particles_explosions_sparks", "1", "enables sparks from explosions"};
Cvar_RegisterVariable (&cl_particles_quake);
Cvar_RegisterVariable (&cl_particles_blood);
Cvar_RegisterVariable (&cl_particles_blood_alpha);
+ Cvar_RegisterVariable (&cl_particles_blood_decal_alpha);
+ Cvar_RegisterVariable (&cl_particles_blood_decal_scalemin);
+ Cvar_RegisterVariable (&cl_particles_blood_decal_scalemax);
Cvar_RegisterVariable (&cl_particles_blood_bloodhack);
Cvar_RegisterVariable (&cl_particles_explosions_sparks);
Cvar_RegisterVariable (&cl_particles_explosions_shell);
matrix4x4_t tempmatrix;
Matrix4x4_CreateFromQuakeEntity(&tempmatrix, originmaxs[0], originmaxs[1], originmaxs[2], 0, 0, 0, light[3]);
R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &tempmatrix, light, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
- r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights++];
+ r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights];r_refdef.scene.numlights++;
}
}
if (ent)
ent->persistent.trail_time = len;
}
- else if (developer.integer >= 1)
- Con_Printf("CL_ParticleEffect_Fallback: no fallback found for effect %s\n", particleeffectname[effectnameindex]);
+ else
+ Con_DPrintf("CL_ParticleEffect_Fallback: no fallback found for effect %s\n", particleeffectname[effectnameindex]);
}
// this is also called on point effects with spawndlight = true and
// these parameters, only trail handling does
void CL_ParticleTrail(int effectnameindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, entity_t *ent, int palettecolor, qboolean spawndlight, qboolean spawnparticles)
{
- vec3_t center;
qboolean found = false;
if (effectnameindex < 1 || effectnameindex >= MAX_PARTICLEEFFECTNAME || !particleeffectname[effectnameindex][0])
{
Con_DPrintf("Unknown effect number %i received from server\n", effectnameindex);
return; // no such effect
}
- VectorLerp(originmins, 0.5, originmaxs, center);
if (!cl_particles_quake.integer && particleeffectinfo[0].effectnameindex)
{
int effectinfoindex;
int tex, staintex;
particleeffectinfo_t *info;
vec3_t center;
- vec3_t centervelocity;
vec3_t traildir;
vec3_t trailpos;
vec3_t rvec;
particle_t *part;
// note this runs multiple effects with the same name, each one spawns only one kind of particle, so some effects need more than one
VectorLerp(originmins, 0.5, originmaxs, center);
- VectorLerp(velocitymins, 0.5, velocitymaxs, centervelocity);
supercontents = CL_PointSuperContents(center);
underwater = (supercontents & (SUPERCONTENTS_WATER | SUPERCONTENTS_SLIME)) != 0;
VectorSubtract(originmaxs, originmins, traildir);
// called by CL_LinkNetworkEntity
Matrix4x4_Scale(&tempmatrix, info->lightradiusstart, 1);
R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &tempmatrix, info->lightcolor, -1, info->lightcubemapnum > 0 ? va("cubemaps/%i", info->lightcubemapnum) : NULL, info->lightshadow, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
- r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights++];
+ r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights];r_refdef.scene.numlights++;
}
}
static void R_InitBloodTextures (unsigned char *particletexturedata)
{
int i, j, k, m;
- unsigned char *data = Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4);
+ size_t datasize = PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4;
+ unsigned char *data = Mem_Alloc(tempmempool, datasize);
// blood particles
for (i = 0;i < 8;i++)
{
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
for (k = 0;k < 24;k++)
particletextureblotch(data, PARTICLETEXTURESIZE/16, 96, 0, 0, 160);
//particletextureclamp(data, 32, 32, 32, 255, 255, 255);
// blood decals
for (i = 0;i < 8;i++)
{
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
m = 8;
for (j = 1;j < 10;j++)
for (k = min(j, m - 1);k < m;k++)
#endif
{
unsigned char *particletexturedata = (unsigned char *)Mem_Alloc(tempmempool, PARTICLEFONTSIZE*PARTICLEFONTSIZE*4);
- unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4);
+ size_t datasize = PARTICLETEXTURESIZE*PARTICLETEXTURESIZE*4;
+ unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, datasize);
unsigned char *noise1 = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*2*PARTICLETEXTURESIZE*2);
unsigned char *noise2 = (unsigned char *)Mem_Alloc(tempmempool, PARTICLETEXTURESIZE*2*PARTICLETEXTURESIZE*2);
// smoke
for (i = 0;i < 8;i++)
{
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
do
{
fractalnoise(noise1, PARTICLETEXTURESIZE*2, PARTICLETEXTURESIZE/8);
}
// rain splash
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
for (y = 0;y < PARTICLETEXTURESIZE;y++)
{
dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
setuptex(tex_rainsplash, data, particletexturedata);
// normal particle
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
for (y = 0;y < PARTICLETEXTURESIZE;y++)
{
dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1);
setuptex(tex_particle, data, particletexturedata);
// rain
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
light[0] = 1;light[1] = 1;light[2] = 1;
VectorNormalize(light);
for (y = 0;y < PARTICLETEXTURESIZE;y++)
setuptex(tex_raindrop, data, particletexturedata);
// bubble
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
light[0] = 1;light[1] = 1;light[2] = 1;
VectorNormalize(light);
for (y = 0;y < PARTICLETEXTURESIZE;y++)
// bullet decals
for (i = 0;i < 8;i++)
{
- memset(data, 255, sizeof(data));
+ memset(data, 255, datasize);
for (k = 0;k < 12;k++)
particletextureblotch(data, PARTICLETEXTURESIZE/16, 0, 0, 0, 128);
for (k = 0;k < 3;k++)
}
#ifndef DUMPPARTICLEFONT
- particletexture[tex_beam].texture = loadtextureimage(particletexturepool, "particles/nexbeam.tga", false, TEXF_ALPHA | TEXF_FORCELINEAR, true);
+ particletexture[tex_beam].texture = loadtextureimage(particletexturepool, "particles/nexbeam.tga", false, TEXF_ALPHA | TEXF_FORCELINEAR, true, r_texture_convertsRGB_particles.integer);
if (!particletexture[tex_beam].texture)
#endif
{
// (this assumes they all use one particle font texture!)
GL_BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
R_SetupShader_Generic(particletexture[63].texture, NULL, GL_MODULATE, 1);
- GL_LockArrays(0, numsurfaces*4);
R_Mesh_Draw(0, numsurfaces * 4, 0, numsurfaces * 2, NULL, particle_elements, 0, 0);
- GL_LockArrays(0, 0);
}
void R_DrawDecals (void)
while (cl.num_decals > 0 && cl.decals[cl.num_decals - 1].typeindex == 0)
cl.num_decals--;
- if (cl.num_decals == cl.max_decals && cl.max_decals < ABSOLUTE_MAX_DECALS)
+ if (cl.num_decals == cl.max_decals && cl.max_decals < MAX_DECALS)
{
decal_t *olddecals = cl.decals;
- cl.max_decals = min(cl.max_decals * 2, ABSOLUTE_MAX_DECALS);
+ cl.max_decals = min(cl.max_decals * 2, MAX_DECALS);
cl.decals = (decal_t *) Mem_Alloc(cls.levelmempool, cl.max_decals * sizeof(decal_t));
memcpy(cl.decals, olddecals, cl.num_decals * sizeof(decal_t));
Mem_Free(olddecals);
// now render batches of particles based on blendmode and texture
blendmode = PBLEND_INVALID;
texture = NULL;
- GL_LockArrays(0, numsurfaces*4);
batchstart = 0;
batchcount = 0;
for (surfacelistindex = 0;surfacelistindex < numsurfaces;)
batchcount = surfacelistindex - batchstart;
R_Mesh_Draw(batchstart * 4, batchcount * 4, batchstart * 2, batchcount * 2, NULL, particle_elements, 0, 0);
}
- GL_LockArrays(0, 0);
}
void R_DrawParticles (void)
{
- int i, a, content;
+ int i, a;
int drawparticles = r_drawparticles.integer;
float minparticledist;
particle_t *p;
- float gravity, dvel, decalfade, frametime, f, dist, oldorg[3];
+ float gravity, frametime, f, dist, oldorg[3];
float drawdist2;
int hitent;
trace_t trace;
minparticledist = DotProduct(r_refdef.view.origin, r_refdef.view.forward) + 4.0f;
gravity = frametime * cl.movevars_gravity;
- dvel = 1+4*frametime;
- decalfade = frametime * 255 / cl_decals_fadetime.value;
update = frametime > 0;
drawdist2 = r_drawparticles_drawdistance.value * r_refdef.view.quality;
drawdist2 = drawdist2*drawdist2;
continue;
p->delayedspawn = 0;
- content = 0;
-
p->size += p->sizeincrease * frametime;
p->alpha -= p->alphafade * frametime;
if (cl_decals.integer)
{
// create a decal for the blood splat
- CL_SpawnDecalParticleForSurface(hitent, p->org, trace.plane.normal, p->color[0] * 65536 + p->color[1] * 256 + p->color[2], p->color[0] * 65536 + p->color[1] * 256 + p->color[2], tex_blooddecal[rand()&7], p->size * 2, p->alpha);
+ CL_SpawnDecalParticleForSurface(hitent, p->org, trace.plane.normal, p->color[0] * 65536 + p->color[1] * 256 + p->color[2], p->color[0] * 65536 + p->color[1] * 256 + p->color[2], tex_blooddecal[rand()&7], p->size * lhrandom(cl_particles_blood_decal_scalemin.value, cl_particles_blood_decal_scalemax.value), cl_particles_blood_decal_alpha.value * 768);
}
}
goto killparticle;
while (cl.num_particles > 0 && cl.particles[cl.num_particles - 1].typeindex == 0)
cl.num_particles--;
- if (cl.num_particles == cl.max_particles && cl.max_particles < ABSOLUTE_MAX_PARTICLES)
+ if (cl.num_particles == cl.max_particles && cl.max_particles < MAX_PARTICLES)
{
particle_t *oldparticles = cl.particles;
- cl.max_particles = min(cl.max_particles * 2, ABSOLUTE_MAX_PARTICLES);
+ cl.max_particles = min(cl.max_particles * 2, MAX_PARTICLES);
cl.particles = (particle_t *) Mem_Alloc(cls.levelmempool, cl.max_particles * sizeof(particle_t));
memcpy(cl.particles, oldparticles, cl.num_particles * sizeof(particle_t));
Mem_Free(oldparticles);