]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_light.c
ent field added back to dlight structures
[xonotic/darkplaces.git] / r_light.c
index 11b4619b2d39653017e23da8835349d46f8a628e..f0660972cbad80fe6a1318e4608436ef8afed148 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -132,7 +132,7 @@ void R_BuildLightList(void)
                        rd->cullradius2 = (2048.0f * 2048.0f);
                rd->cullradius = sqrt(rd->cullradius2);
                rd->subtract = 1.0f / rd->cullradius2;
-               //rd->ent = cd->ent;
+               rd->ent = cd->ent;
                c_dlights++; // count every dlight in use
        }
 }
@@ -148,19 +148,18 @@ void R_DrawCoronas(void)
        memset(&m, 0, sizeof(m));
        m.blendfunc1 = GL_ONE;
        m.blendfunc2 = GL_ONE;
-       m.wantoverbright = false;
        m.depthdisable = true; // magic
        m.tex[0] = R_GetTexture(lightcorona);
-       Matrix4x4_CreateIdentity(&m.matrix);
+       R_Mesh_Matrix(&r_identitymatrix);
        R_Mesh_State(&m);
        viewdist = DotProduct(r_origin, vpn);
        for (i = 0;i < r_numdlights;i++)
        {
                rd = r_dlight + i;
                dist = (DotProduct(rd->origin, vpn) - viewdist);
-               if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, 0, true) == 1)
+               if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, 0, true, NULL) == 1)
                {
-                       scale = mesh_colorscale * (1.0f / 131072.0f);
+                       scale = r_colorscale * (1.0f / 131072.0f);
                        if (gl_flashblend.integer)
                                scale *= 4.0f;
                        if (fogenabled)
@@ -168,12 +167,6 @@ void R_DrawCoronas(void)
                                VectorSubtract(rd->origin, r_origin, diff);
                                scale *= 1 - exp(fogdensity/DotProduct(diff,diff));
                        }
-                       varray_element[0] = 0;
-                       varray_element[1] = 1;
-                       varray_element[2] = 2;
-                       varray_element[3] = 0;
-                       varray_element[4] = 2;
-                       varray_element[5] = 3;
                        varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = rd->light[0] * scale;
                        varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = rd->light[1] * scale;
                        varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = rd->light[2] * scale;
@@ -201,7 +194,7 @@ void R_DrawCoronas(void)
                        varray_vertex[12] = rd->origin[0] + vright[0] * scale - vup[0] * scale;
                        varray_vertex[13] = rd->origin[1] + vright[1] * scale - vup[1] * scale;
                        varray_vertex[14] = rd->origin[2] + vright[2] * scale - vup[2] * scale;
-                       R_Mesh_Draw(4, 2);
+                       R_Mesh_Draw(4, 2, polygonelements);
                }
        }
 }
@@ -219,11 +212,12 @@ DYNAMIC LIGHTS
 R_MarkLights
 =============
 */
+extern int r_pvsframecount;
 static void R_OldMarkLights (entity_render_t *ent, vec3_t lightorigin, rdlight_t *rd, int bit, int bitindex, mnode_t *node)
 {
        float ndist, maxdist;
        msurface_t *surf;
-       int i;
+       int i, *surfacepvsframes;
        int d, impacts, impactt;
        float dist, dist2, impact[3];
 
@@ -233,6 +227,7 @@ static void R_OldMarkLights (entity_render_t *ent, vec3_t lightorigin, rdlight_t
        // for comparisons to minimum acceptable light
        maxdist = rd->cullradius2;
 
+       surfacepvsframes = ent->model->surfacepvsframes;
 loc0:
        if (node->contents < 0)
                return;
@@ -254,7 +249,7 @@ loc0:
        surf = ent->model->surfaces + node->firstsurface;
        for (i = 0;i < node->numsurfaces;i++, surf++)
        {
-               if (surf->visframe != r_framecount)
+               if (surfacepvsframes[surf->number] != r_pvsframecount)
                        continue;
                dist = ndist;
                if (surf->flags & SURF_PLANEBACK)
@@ -329,8 +324,8 @@ static void R_VisMarkLights (entity_render_t *ent, rdlight_t *rd, int bit, int b
        mleaf_t *pvsleaf;
        vec3_t lightorigin;
        model_t *model;
-       int i, k, m, c, leafnum;
-       msurface_t *surf, **mark;
+       int i, k, m, c, leafnum, *surfacepvsframes, *mark;
+       msurface_t *surf;
        mleaf_t *leaf;
        qbyte *in;
        int row;
@@ -363,6 +358,7 @@ static void R_VisMarkLights (entity_render_t *ent, rdlight_t *rd, int bit, int b
        maxdist = rd->cullradius2;
 
        row = (model->numleafs+7)>>3;
+       surfacepvsframes = model->surfacepvsframes;
 
        k = 0;
        while (k < row)
@@ -388,12 +384,12 @@ static void R_VisMarkLights (entity_render_t *ent, rdlight_t *rd, int bit, int b
                                                mark = leaf->firstmarksurface;
                                                do
                                                {
-                                                       surf = *mark++;
+                                                       surf = model->surfaces + *mark++;
                                                        // if not visible in current frame, or already marked because it was in another leaf we passed, skip
                                                        if (surf->lightframe == lightframe)
                                                                continue;
                                                        surf->lightframe = lightframe;
-                                                       if (surf->visframe != r_framecount)
+                                                       if (surfacepvsframes[surf->number] != r_pvsframecount)
                                                                continue;
                                                        dist = PlaneDiff(lightorigin, surf->plane);
                                                        if (surf->flags & SURF_PLANEBACK)
@@ -632,7 +628,7 @@ void R_CompleteLightPoint (vec3_t color, const vec3_t p, int dynamic, const mlea
                        {
                                VectorSubtract (p, sl->origin, v);
                                f = ((1.0f / (DotProduct(v, v) * sl->falloff + sl->distbias)) - sl->subtract);
-                               if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, 0, false) == 1)
+                               if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, 0, false, NULL) == 1)
                                {
                                        f *= d_lightstylevalue[sl->style] * (1.0f / 65536.0f);
                                        VectorMA(color, f, sl->light, color);
@@ -650,7 +646,7 @@ void R_CompleteLightPoint (vec3_t color, const vec3_t p, int dynamic, const mlea
                        rd = r_dlight + i;
                        VectorSubtract (p, rd->origin, v);
                        f = DotProduct(v, v);
-                       if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, 0, false) == 1)
+                       if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, 0, false, NULL) == 1)
                        {
                                f = (1.0f / (f + LIGHTOFFSET)) - rd->subtract;
                                VectorMA(color, f, rd->light, color);
@@ -763,7 +759,7 @@ void R_LightModel(const entity_render_t *ent, int numverts, float colorr, float
                        VectorSubtract (v, rd->origin, v);
                        if (DotProduct(v, v) < rd->cullradius2)
                        {
-                               if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, 0, false) != 1)
+                               if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, 0, false, NULL) != 1)
                                        continue;
                                VectorSubtract (ent->origin, rd->origin, v);
                                f = ((1.0f / (DotProduct(v, v) + LIGHTOFFSET)) - rd->subtract);
@@ -905,7 +901,7 @@ void R_UpdateEntLights(entity_render_t *ent)
                ent->numentlights = 0;
                if (cl.worldmodel)
                        for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights && ent->numentlights < MAXENTLIGHTS;i++, sl++)
-                               if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, 0, false) == 1)
+                               if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, 0, false, NULL) == 1)
                                        ent->entlights[ent->numentlights++] = i;
        }
        ent->entlightsframe = r_framecount;