optimizations to rendering
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 28 Aug 2002 14:33:20 +0000 (14:33 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 28 Aug 2002 14:33:20 +0000 (14:33 +0000)
particle lighting is no longer supported, sorry
particle visibility is no longer checked, it was wasting too much time

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2299 d7cf8633-e32d-0410-b094-e92efae38249

cl_particles.c
gl_backend.c
gl_rmain.c
gl_rsurf.c
render.h

index a2d0094..c46bc83 100644 (file)
@@ -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;\
@@ -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,7 +1176,6 @@ 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);
 }
 
@@ -1185,83 +1183,17 @@ 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;
        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;
-       if (orientation == PARTICLE_BILLBOARD)
-       {
-               VectorScale(vright, p->scalex, right);
-               VectorScale(vup, p->scaley, up);
-       }
-       else if (orientation == PARTICLE_UPRIGHT_FACING)
-       {
-               v[0] = r_origin[0] - org[0];
-               v[1] = r_origin[1] - org[1];
-               v[2] = 0;
-               VectorNormalizeFast(v);
-               VectorVectors(v, right2, up2);
-               VectorScale(right2, p->scalex, right);
-               VectorScale(up2, p->scaley, up);
-       }
-       else if (orientation == PARTICLE_ORIENTED_DOUBLESIDED)
-       {
-               // double-sided
-               if (DotProduct(p->vel2, r_origin) > DotProduct(p->vel2, org))
-               {
-                       VectorNegate(p->vel2, v);
-                       VectorVectors(v, right, up);
-               }
-               else
-                       VectorVectors(p->vel2, right, up);
-               VectorScale(right, p->scalex, right);
-               VectorScale(up, p->scaley, up);
-       }
-       else
-               Host_Error("R_DrawParticles: unknown particle orientation %i\n", orientation);
-
-       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);
-               fog = exp(fogdensity/DotProduct(fogvec,fogvec));
-               ifog = 1 - fog;
-               cr = cr * ifog;
-               cg = cg * ifog;
-               cb = cb * ifog;
-               if (!additive)
-               {
-                       cr += fogcolor[0] * fog;
-                       cg += fogcolor[1] * fog;
-                       cb += fogcolor[2] * fog;
-               }
-       }
 
        memset(&m, 0, sizeof(m));
        m.blendfunc1 = GL_SRC_ALPHA;
@@ -1281,6 +1213,36 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                m.index[3] = 0;
                m.index[4] = 2;
                m.index[5] = 3;
+               if (orientation == PARTICLE_BILLBOARD)
+               {
+                       VectorScale(vright, p->scalex, right);
+                       VectorScale(vup, p->scaley, up);
+               }
+               else if (orientation == PARTICLE_UPRIGHT_FACING)
+               {
+                       v[0] = r_origin[0] - org[0];
+                       v[1] = r_origin[1] - org[1];
+                       v[2] = 0;
+                       VectorNormalizeFast(v);
+                       VectorVectors(v, right2, up2);
+                       VectorScale(right2, p->scalex, right);
+                       VectorScale(up2, p->scaley, up);
+               }
+               else if (orientation == PARTICLE_ORIENTED_DOUBLESIDED)
+               {
+                       // double-sided
+                       if (DotProduct(p->vel2, r_origin) > DotProduct(p->vel2, org))
+                       {
+                               VectorNegate(p->vel2, v);
+                               VectorVectors(v, right, up);
+                       }
+                       else
+                               VectorVectors(p->vel2, right, up);
+                       VectorScale(right, p->scalex, right);
+                       VectorScale(up, p->scaley, up);
+               }
+               else
+                       Host_Error("R_DrawParticles: unknown particle orientation %i\n", orientation);
                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];
@@ -1302,6 +1264,25 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                m.texcoords[0][5] = tex->t2;
                m.texcoords[0][6] = tex->s2;
                m.texcoords[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 (fogenabled)
+               {
+                       VectorSubtract(org, r_origin, fogvec);
+                       fog = exp(fogdensity/DotProduct(fogvec,fogvec));
+                       ifog = 1 - fog;
+                       cr = cr * ifog;
+                       cg = cg * ifog;
+                       cb = cb * ifog;
+                       if (!additive)
+                       {
+                               cr += fogcolor[0] * fog;
+                               cg += fogcolor[1] * fog;
+                               cb += fogcolor[2] * fog;
+                       }
+               }
                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;
@@ -1330,6 +1311,10 @@ void R_DrawParticles (void)
                if (DotProduct(p->org, vpn) < minparticledist)
                        continue;
 
+               // LordHavoc: check if it's in a visible leaf
+               //if (Mod_PointInLeaf(p->org, cl.worldmodel)->visframe != r_framecount)
+               //      continue;
+
                R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
        }
 }
index aa4679e..dec7eeb 100644 (file)
@@ -711,7 +711,7 @@ void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *in
 void R_Mesh_Render(void)
 {
        int i, k;
-       float *v, tempv[4];
+       float *v, tempv[4], m[12];
        buf_mesh_t *mesh;
 
        if (!backendactive)
@@ -743,10 +743,25 @@ void R_Mesh_Render(void)
        GL_MeshState(buf_mesh);
        for (k = 0, mesh = buf_mesh;k < currentmesh;k++, mesh++)
        {
+               m[0] = mesh->matrix.m[0][0];
+               m[1] = mesh->matrix.m[0][1];
+               m[2] = mesh->matrix.m[0][2];
+               m[3] = mesh->matrix.m[0][3];
+               m[4] = mesh->matrix.m[1][0];
+               m[5] = mesh->matrix.m[1][1];
+               m[6] = mesh->matrix.m[1][2];
+               m[7] = mesh->matrix.m[1][3];
+               m[8] = mesh->matrix.m[2][0];
+               m[9] = mesh->matrix.m[2][1];
+               m[10] = mesh->matrix.m[2][2];
+               m[11] = mesh->matrix.m[2][3];
                for (i = 0, v = buf_vertex[mesh->firstvert].v;i < mesh->verts;i++, v += 4)
                {
                        VectorCopy(v, tempv);
-                       Matrix4x4_Transform(&mesh->matrix, tempv, v);
+                       //Matrix4x4_Transform(&mesh->matrix, tempv, v);
+                       v[0] = tempv[0] * m[0] + tempv[1] * m[1] + tempv[2] * m[2] + m[3];
+                       v[1] = tempv[0] * m[4] + tempv[1] * m[5] + tempv[2] * m[6] + m[7];
+                       v[2] = tempv[0] * m[8] + tempv[1] * m[9] + tempv[2] * m[10] + m[11];
                }
        }
        GL_LockArray(0, currentvertex);
index 09c48a7..d0a46fa 100644 (file)
@@ -635,7 +635,7 @@ void R_RenderView (void)
        R_MarkEntities();
        R_TimeReport("markentity");
 
-       R_MarkWorldLights(world);
+       R_SurfMarkLights(world);
        R_TimeReport("marklights");
 
        r_farclip = R_FarClip_Finish() + 256.0f;
@@ -656,7 +656,6 @@ void R_RenderView (void)
                R_TimeReport("viewmodel");
        }
 
-       R_SetupForWorldRendering(world);
        R_PrepareSurfaces(world);
        R_TimeReport("surfprep");
 
index eae22ed..c4ececd 100644 (file)
@@ -1919,13 +1919,7 @@ void R_SetupForBModelRendering(entity_render_t *ent)
        }
 }
 
-void R_SetupForWorldRendering(entity_render_t *ent)
-{
-       // there is only one instance of the world, but it can be rendered in
-       // multiple stages
-}
-
-static void R_SurfMarkLights (entity_render_t *ent)
+void R_SurfMarkLights (entity_render_t *ent)
 {
        int                     i;
        msurface_t      *surf;
@@ -1959,12 +1953,6 @@ static void R_SurfMarkLights (entity_render_t *ent)
        }
 }
 
-void R_MarkWorldLights(entity_render_t *ent)
-{
-       R_SetupForWorldRendering(ent);
-       R_SurfMarkLights(ent);
-}
-
 /*
 =============
 R_DrawWorld
@@ -1972,8 +1960,8 @@ R_DrawWorld
 */
 void R_DrawWorld (entity_render_t *ent)
 {
-       R_SetupForWorldRendering(ent);
-
+       // there is only one instance of the world, but it can be rendered in
+       // multiple stages
        if (r_viewleaf->contents == CONTENTS_SOLID || r_novis.integer || r_viewleaf->compressed_vis == NULL)
                R_SolidWorldNode (ent);
        else
index c3a5e09..a22cad7 100644 (file)
--- a/render.h
+++ b/render.h
@@ -111,8 +111,7 @@ void R_InitSky (qbyte *src, int bytesperpixel); // called at level load
 void R_NewMap (void);
 
 void R_DrawWorld(entity_render_t *ent);
-void R_SetupForWorldRendering(entity_render_t *ent);
-void R_MarkWorldLights(entity_render_t *ent);
+void R_SurfMarkLights (entity_render_t *ent);
 void R_PrepareSurfaces(entity_render_t *ent);
 void R_DrawSurfaces(entity_render_t *ent, int type);
 void R_DrawPortals(entity_render_t *ent);