early steps toward support for persistent caching of dlight shadows
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 12 Feb 2009 06:25:05 +0000 (06:25 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 12 Feb 2009 06:25:05 +0000 (06:25 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8703 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_particles.c
client.h
clvm_cmds.c
r_shadow.c

index fb6d968..48bcae8 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -750,7 +750,9 @@ void CL_RelinkLightFlashes(void)
                        {
                                tempmatrix = dl->matrix;
                                Matrix4x4_Scale(&tempmatrix, dl->radius, 1);
-                               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &tempmatrix, dl->color, dl->style, dl->cubemapname, dl->shadow, dl->corona, dl->coronasizescale, dl->ambientscale, dl->diffusescale, dl->specularscale, dl->flags);
+                               // we need the corona fading to be persistent
+                               R_RTLight_Update(&dl->rtlight, false, &tempmatrix, dl->color, dl->style, dl->cubemapname, dl->shadow, dl->corona, dl->coronasizescale, dl->ambientscale, dl->diffusescale, dl->specularscale, dl->flags);
+                               r_refdef.scene.lights[r_refdef.scene.numlights++] = &dl->rtlight;
                        }
                }
        }
@@ -1361,7 +1363,8 @@ void CL_LinkNetworkEntity(entity_t *e)
                Matrix4x4_SetOrigin(&tempmatrix, trace.endpos[0], trace.endpos[1], trace.endpos[2]);
                Matrix4x4_Scale(&tempmatrix, 150, 1);
                VectorSet(color, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f);
-               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &tempmatrix, color, -1, NULL, true, 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+               R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &tempmatrix, color, -1, NULL, true, 0, 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++];
        }
        // LordHavoc: if the model has no flags, don't check each
        if (e->render.model && e->render.effects && !(e->render.flags & RENDER_VIEWMODEL))
@@ -1392,17 +1395,6 @@ void CL_LinkNetworkEntity(entity_t *e)
                dlightradius = max(dlightradius, e->state_current.glowsize * 4);
                VectorMA(dlightcolor, (1.0f / 255.0f), palette_rgb[e->state_current.glowcolor], dlightcolor);
        }
-       // make the glow dlight
-       if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL) && r_refdef.scene.numlights < MAX_DLIGHTS)
-       {
-               matrix4x4_t dlightmatrix;
-               Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
-               // hack to make glowing player light shine on their gun
-               //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
-               //      Matrix4x4_AdjustOrigin(&dlightmatrix, 0, 0, 30);
-               Matrix4x4_Scale(&dlightmatrix, dlightradius, 1);
-               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &dlightmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
-       }
        // custom rtlight
        if ((e->state_current.lightpflags & PFLAGS_FULLDYNAMIC) && r_refdef.scene.numlights < MAX_DLIGHTS)
        {
@@ -1417,7 +1409,20 @@ void CL_LinkNetworkEntity(entity_t *e)
                // FIXME: add ambient/diffuse/specular scales as an extension ontop of TENEBRAE_GFX_DLIGHTS?
                Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
                Matrix4x4_Scale(&dlightmatrix, light[3], 1);
-               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &dlightmatrix, light, e->state_current.lightstyle, e->state_current.skin > 0 ? va("cubemaps/%i", e->state_current.skin) : NULL, !(e->state_current.lightpflags & PFLAGS_NOSHADOW), (e->state_current.lightpflags & PFLAGS_CORONA) != 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+               R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &dlightmatrix, light, e->state_current.lightstyle, e->state_current.skin > 0 ? va("cubemaps/%i", e->state_current.skin) : NULL, !(e->state_current.lightpflags & PFLAGS_NOSHADOW), (e->state_current.lightpflags & PFLAGS_CORONA) != 0, 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++];
+       }
+       // make the glow dlight
+       else if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL) && r_refdef.scene.numlights < MAX_DLIGHTS)
+       {
+               matrix4x4_t dlightmatrix;
+               Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
+               // hack to make glowing player light shine on their gun
+               //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
+               //      Matrix4x4_AdjustOrigin(&dlightmatrix, 0, 0, 30);
+               Matrix4x4_Scale(&dlightmatrix, dlightradius, 1);
+               R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &dlightmatrix, dlightcolor, -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++];
        }
        // do trail light
        if (e->render.flags & RENDER_GLOWTRAIL)
@@ -1618,7 +1623,8 @@ void CL_RelinkBeams(void)
                                vec3_t dlightcolor;
                                VectorSet(dlightcolor, 0.3, 0.7, 1);
                                Matrix4x4_CreateFromQuakeEntity(&tempmatrix, end[0], end[1], end[2], 0, 0, 0, 200);
-                               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &tempmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+                               R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &tempmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+                               r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights++];
                        }
                        if (cl_beams_polygons.integer)
                                continue;
index b373062..06f745b 100644 (file)
@@ -969,7 +969,8 @@ void CL_ParticleEffect_Fallback(int effectnameindex, float count, const vec3_t o
                        {
                                matrix4x4_t tempmatrix;
                                Matrix4x4_CreateFromQuakeEntity(&tempmatrix, originmaxs[0], originmaxs[1], originmaxs[2], 0, 0, 0, light[3]);
-                               R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &tempmatrix, light, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+                               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++];
                        }
                }
 
@@ -1217,8 +1218,8 @@ void CL_ParticleTrail(int effectnameindex, float pcount, const vec3_t originmins
                                                // glowing entity
                                                // called by CL_LinkNetworkEntity
                                                Matrix4x4_Scale(&tempmatrix, info->lightradiusstart, 1);
-                                               if(r_refdef.scene.numlights < MAX_DLIGHTS)
-                                                       R_RTLight_Update(&r_refdef.scene.lights[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_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++];
                                        }
                                }
 
index d75c5e2..4c52a63 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1492,7 +1492,8 @@ typedef struct r_refdef_scene_s {
        int maxtempentities;
 
        // renderable dynamic lights
-       rtlight_t lights[MAX_DLIGHTS];
+       rtlight_t *lights[MAX_DLIGHTS];
+       rtlight_t templights[MAX_DLIGHTS];
        int numlights;
 
        // intensities for light styles right now, controls rtlights
index 18a7b86..8cb4f38 100644 (file)
@@ -917,7 +917,8 @@ void VM_CL_R_AddDynamicLight (void)
        VectorScale(prog->globals.client->v_up, radius, up);
        Matrix4x4_FromVectors(&matrix, forward, left, up, org);
 
-       R_RTLight_Update(&r_refdef.scene.lights[r_refdef.scene.numlights++], false, &matrix, col, style, cubemapname, castshadow, coronaintensity, coronasizescale, ambientscale, diffusescale, specularscale, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+       R_RTLight_Update(&r_refdef.scene.templights[r_refdef.scene.numlights], false, &matrix, col, style, cubemapname, castshadow, coronaintensity, coronasizescale, ambientscale, diffusescale, specularscale, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+       r_refdef.scene.lights[r_refdef.scene.numlights] = &r_refdef.scene.templights[r_refdef.scene.numlights++];
 }
 
 //============================================================================
index cfb1d58..1c3275d 100644 (file)
@@ -3175,7 +3175,7 @@ void R_ShadowVolumeLighting(qboolean visible)
        }
        if (r_refdef.scene.rtdlight)
                for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++)
-                       R_DrawRTLight(&r_refdef.scene.lights[lnum], visible);
+                       R_DrawRTLight(r_refdef.scene.lights[lnum], visible);
 
        R_Shadow_RenderMode_End();
 }
@@ -3412,7 +3412,7 @@ void R_DrawCoronas(void)
        }
        for (i = 0;i < r_refdef.scene.numlights;i++)
        {
-               rtlight = &r_refdef.scene.lights[i];
+               rtlight = r_refdef.scene.lights[i];
                rtlight->corona_visibility = 0;
                rtlight->corona_queryindex_visiblepixels = 0;
                rtlight->corona_queryindex_allpixels = 0;
@@ -3438,7 +3438,7 @@ void R_DrawCoronas(void)
        }
        for (i = 0;i < r_refdef.scene.numlights;i++)
        {
-               rtlight = &r_refdef.scene.lights[i];
+               rtlight = r_refdef.scene.lights[i];
                if (rtlight->corona_visibility <= 0)
                        continue;
                if (gl_flashblend.integer)
@@ -4847,7 +4847,7 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu
                rtlight_t *light;
                for (i = 0;i < r_refdef.scene.numlights;i++)
                {
-                       light = &r_refdef.scene.lights[i];
+                       light = r_refdef.scene.lights[i];
                        Matrix4x4_Transform(&light->matrix_worldtolight, p, v);
                        f = 1 - VectorLength2(v);
                        if (f > 0 && CL_Move(p, vec3_origin, vec3_origin, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1)