]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_particles.c
m.wantoverbright is gone
[xonotic/darkplaces.git] / cl_particles.c
index a2d00944b07991bc8680931228341fcac9fb0fc0..9342d8edc6b19dcc4430fa2563145ed8e67d5f74 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "cl_collision.h"
 
-#define MAX_PARTICLES                  16384   // default max # of particles at one time
+#define MAX_PARTICLES                  8192    // default max # of particles at one time
 #define ABSOLUTE_MIN_PARTICLES 512             // no fewer than this no matter what's on the command line
 
 typedef enum
@@ -35,7 +35,7 @@ ptype_t;
 #define P_ORIENTATION_FIRSTBIT (P_TEXNUM_FIRSTBIT + P_TEXNUM_BITS)
 #define P_ORIENTATION_BITS 2
 #define P_FLAGS_FIRSTBIT (P_ORIENTATION_FIRSTBIT + P_ORIENTATION_BITS)
-#define P_DYNLIGHT (1 << (P_FLAGS_FIRSTBIT + 0))
+//#define P_DYNLIGHT (1 << (P_FLAGS_FIRSTBIT + 0))
 #define P_ADDITIVE (1 << (P_FLAGS_FIRSTBIT + 1))
 
 typedef struct particle_s
@@ -179,8 +179,8 @@ void CL_Particles_Init (void)
                partflags = ((porientation) << P_ORIENTATION_FIRSTBIT) | ((ptex) << P_TEXNUM_FIRSTBIT);\
                if (padditive)\
                        partflags |= P_ADDITIVE;\
-               if (plight)\
-                       partflags |= P_DYNLIGHT;\
+               /*if (plight)*/\
+               /*      partflags |= P_DYNLIGHT;*/\
                tempcolor = (pcolor1);\
                tempcolor2 = (pcolor2);\
                cr2 = ((tempcolor2) >> 16) & 0xFF;\
@@ -351,7 +351,7 @@ void CL_ParticleExplosion (vec3_t org, int smoke)
        if (cl_stainmaps.integer)
                R_Stain(org, 96, 80, 80, 80, 64, 176, 176, 176, 64);
 
-       i = Mod_PointInLeaf(org, cl.worldmodel)->contents;
+       i = Mod_PointContents(org, cl.worldmodel);
        if ((i == CONTENTS_SLIME || i == CONTENTS_WATER) && cl_particles.integer && cl_particles_bubbles.integer)
        {
                for (i = 0;i < 128;i++)
@@ -432,7 +432,7 @@ void CL_SparkShower (vec3_t org, vec3_t dir, int count)
        if (!cl_particles.integer) return;
 
        if (cl_stainmaps.integer)
-               R_Stain(org, 32, 96, 96, 96, 2, 128, 128, 128, 2);
+               R_Stain(org, 32, 96, 96, 96, 24, 128, 128, 128, 24);
 
        if (cl_particles_bulletimpacts.integer)
        {
@@ -455,7 +455,7 @@ void CL_SparkShower (vec3_t org, vec3_t dir, int count)
 void CL_PlasmaBurn (vec3_t org)
 {
        if (cl_stainmaps.integer)
-               R_Stain(org, 48, 96, 96, 96, 3, 128, 128, 128, 3);
+               R_Stain(org, 48, 96, 96, 96, 32, 128, 128, 128, 32);
 }
 
 static float bloodcount = 0;
@@ -717,7 +717,7 @@ void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
        // if we skip out, leave it reset
        ent->persistent.trail_time = 0.0f;
 
-       contents = Mod_PointInLeaf(pos, cl.worldmodel)->contents;
+       contents = Mod_PointContents(pos, cl.worldmodel);
        if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
                return;
 
@@ -860,7 +860,7 @@ void CL_MoveParticles (void)
                                {
                                        // assume it's blood (lame, but...)
                                        if (cl_stainmaps.integer)
-                                               R_Stain(v, 32, 32, 16, 16, p->alpha * p->scalex * (1.0f / 400.0f), 192, 48, 48, p->alpha * p->scalex * (1.0f / 400.0f));
+                                               R_Stain(v, 32, 32, 16, 16, p->alpha * p->scalex * (1.0f / 40.0f), 192, 48, 48, p->alpha * p->scalex * (1.0f / 40.0f));
                                        p->die = -1;
                                        freeparticles[j++] = p;
                                        continue;
@@ -880,7 +880,7 @@ void CL_MoveParticles (void)
                {
                        f = p->friction * frametime;
                        if (!content)
-                               content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
+                               content = Mod_PointContents(p->org, cl.worldmodel);
                        if (content != CONTENTS_EMPTY)
                                f *= 4;
                        f = 1.0f - f;
@@ -893,7 +893,7 @@ void CL_MoveParticles (void)
                        {
                        case pt_blood:
                                if (!content)
-                                       content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
+                                       content = Mod_PointContents(p->org, cl.worldmodel);
                                a = content;
                                if (a != CONTENTS_EMPTY)
                                {
@@ -911,7 +911,7 @@ void CL_MoveParticles (void)
                                break;
                        case pt_bubble:
                                if (!content)
-                                       content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
+                                       content = Mod_PointContents(p->org, cl.worldmodel);
                                if (content != CONTENTS_WATER && content != CONTENTS_SLIME)
                                {
                                        p->die = -1;
@@ -928,7 +928,7 @@ void CL_MoveParticles (void)
                                        p->vel[2] = /*lhrandom(-32, 32) +*/ p->vel2[2];
                                }
                                if (!content)
-                                       content = Mod_PointInLeaf(p->org, cl.worldmodel)->contents;
+                                       content = Mod_PointContents(p->org, cl.worldmodel);
                                a = content;
                                if (a != CONTENTS_EMPTY && a != CONTENTS_SKY)
                                        p->die = -1;
@@ -1005,7 +1005,6 @@ static rtexture_t *particlefonttexture;
 static particletexture_t particletexture[MAX_PARTICLETEXTURES];
 
 static cvar_t r_drawparticles = {0, "r_drawparticles", "1"};
-static cvar_t r_particles_lighting = {0, "r_particles_lighting", "0"};
 
 static qbyte shadebubble(float dx, float dy, vec3_t light)
 {
@@ -1177,33 +1176,33 @@ static void r_part_newmap(void)
 void R_Particles_Init (void)
 {
        Cvar_RegisterVariable(&r_drawparticles);
-       Cvar_RegisterVariable(&r_particles_lighting);
        R_RegisterModule("R_Particles", r_part_start, r_part_shutdown, r_part_newmap);
 }
 
-int partindexarray[6] = {0, 1, 2, 0, 2, 3};
-
 void R_DrawParticleCallback(const void *calldata1, int calldata2)
 {
-       int lighting, dynlight, additive, texnum, orientation;
+       int additive, texnum, orientation;
        float org[3], up2[3], right2[3], v[3], right[3], up[3], fog, ifog, fogvec[3], cr, cg, cb, ca;
        particletexture_t *tex;
-       mleaf_t *leaf;
-       rmeshbufferinfo_t m;
+       rmeshstate_t m;
        const particle_t *p = calldata1;
 
-       // LordHavoc: check if it's in a visible leaf
-       leaf = Mod_PointInLeaf(p->org, cl.worldmodel);
-       if (leaf->visframe != r_framecount)
-               return;
-
-       lighting = r_dynamic.integer ? r_particles_lighting.integer : 0;
-
        VectorCopy(p->org, org);
        orientation = (p->flags >> P_ORIENTATION_FIRSTBIT) & ((1 << P_ORIENTATION_BITS) - 1);
        texnum = (p->flags >> P_TEXNUM_FIRSTBIT) & ((1 << P_TEXNUM_BITS) - 1);
-       dynlight = p->flags & P_DYNLIGHT;
+       //dynlight = p->flags & P_DYNLIGHT;
        additive = p->flags & P_ADDITIVE;
+
+       memset(&m, 0, sizeof(m));
+       m.blendfunc1 = GL_SRC_ALPHA;
+       if (additive)
+               m.blendfunc2 = GL_ONE;
+       else
+               m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
+       m.tex[0] = R_GetTexture(particlefonttexture);
+       R_Mesh_Matrix(&r_identitymatrix);
+       R_Mesh_State(&m);
+
        if (orientation == PARTICLE_BILLBOARD)
        {
                VectorScale(vright, p->scalex, right);
@@ -1234,19 +1233,31 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
        }
        else
                Host_Error("R_DrawParticles: unknown particle orientation %i\n", orientation);
-
+       varray_vertex[0] = org[0] - right[0] - up[0];
+       varray_vertex[1] = org[1] - right[1] - up[1];
+       varray_vertex[2] = org[2] - right[2] - up[2];
+       varray_vertex[4] = org[0] - right[0] + up[0];
+       varray_vertex[5] = org[1] - right[1] + up[1];
+       varray_vertex[6] = org[2] - right[2] + up[2];
+       varray_vertex[8] = org[0] + right[0] + up[0];
+       varray_vertex[9] = org[1] + right[1] + up[1];
+       varray_vertex[10] = org[2] + right[2] + up[2];
+       varray_vertex[12] = org[0] + right[0] - up[0];
+       varray_vertex[13] = org[1] + right[1] - up[1];
+       varray_vertex[14] = org[2] + right[2] - up[2];
+       tex = &particletexture[texnum];
+       varray_texcoord[0][0] = tex->s1;
+       varray_texcoord[0][1] = tex->t1;
+       varray_texcoord[0][2] = tex->s1;
+       varray_texcoord[0][3] = tex->t2;
+       varray_texcoord[0][4] = tex->s2;
+       varray_texcoord[0][5] = tex->t2;
+       varray_texcoord[0][6] = tex->s2;
+       varray_texcoord[0][7] = tex->t1;
        cr = p->color[0] * (1.0f / 255.0f);
        cg = p->color[1] * (1.0f / 255.0f);
        cb = p->color[2] * (1.0f / 255.0f);
        ca = p->alpha * (1.0f / 255.0f);
-       if (lighting >= 1 && (dynlight || lighting >= 2))
-       {
-               R_CompleteLightPoint(v, org, true, leaf);
-               cr *= v[0];
-               cg *= v[1];
-               cb *= v[2];
-       }
-
        if (fogenabled)
        {
                VectorSubtract(org, r_origin, fogvec);
@@ -1262,52 +1273,11 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                        cb += fogcolor[2] * fog;
                }
        }
-
-       memset(&m, 0, sizeof(m));
-       m.blendfunc1 = GL_SRC_ALPHA;
-       if (additive)
-               m.blendfunc2 = GL_ONE;
-       else
-               m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       m.numtriangles = 2;
-       m.numverts = 4;
-       m.tex[0] = R_GetTexture(particlefonttexture);
-       Matrix4x4_CreateIdentity(&m.matrix);
-       if (R_Mesh_Draw_GetBuffer(&m, false))
-       {
-               m.index[0] = 0;
-               m.index[1] = 1;
-               m.index[2] = 2;
-               m.index[3] = 0;
-               m.index[4] = 2;
-               m.index[5] = 3;
-               m.vertex[0] = org[0] - right[0] - up[0];
-               m.vertex[1] = org[1] - right[1] - up[1];
-               m.vertex[2] = org[2] - right[2] - up[2];
-               m.vertex[4] = org[0] - right[0] + up[0];
-               m.vertex[5] = org[1] - right[1] + up[1];
-               m.vertex[6] = org[2] - right[2] + up[2];
-               m.vertex[8] = org[0] + right[0] + up[0];
-               m.vertex[9] = org[1] + right[1] + up[1];
-               m.vertex[10] = org[2] + right[2] + up[2];
-               m.vertex[12] = org[0] + right[0] - up[0];
-               m.vertex[13] = org[1] + right[1] - up[1];
-               m.vertex[14] = org[2] + right[2] - up[2];
-               tex = &particletexture[texnum];
-               m.texcoords[0][0] = tex->s1;
-               m.texcoords[0][1] = tex->t1;
-               m.texcoords[0][2] = tex->s1;
-               m.texcoords[0][3] = tex->t2;
-               m.texcoords[0][4] = tex->s2;
-               m.texcoords[0][5] = tex->t2;
-               m.texcoords[0][6] = tex->s2;
-               m.texcoords[0][7] = tex->t1;
-               m.color[0] = m.color[4] = m.color[8] = m.color[12] = cr * m.colorscale;
-               m.color[1] = m.color[5] = m.color[9] = m.color[13] = cg * m.colorscale;
-               m.color[2] = m.color[6] = m.color[10] = m.color[14] = cb * m.colorscale;
-               m.color[3] = m.color[7] = m.color[11] = m.color[15] = ca;
-               R_Mesh_Render();
-       }
+       varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = cr * r_colorscale;
+       varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = cg * r_colorscale;
+       varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = cb * r_colorscale;
+       varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = ca;
+       R_Mesh_Draw(4, 2, polygonelements);
 }
 
 void R_DrawParticles (void)
@@ -1324,13 +1294,9 @@ void R_DrawParticles (void)
 
        minparticledist = DotProduct(r_origin, vpn) + 16.0f;
 
+       // LordHavoc: only render if not too close
        for (i = 0, p = particles;i < cl_numparticles;i++, p++)
-       {
-               // LordHavoc: only render if not too close
-               if (DotProduct(p->org, vpn) < minparticledist)
-                       continue;
-
-               R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
-       }
+               if (DotProduct(p->org, vpn) >= minparticledist)
+                       R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
 }