]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
support skin and pflags in light entity loader
[xonotic/darkplaces.git] / r_shadow.c
index ce3cc8dcbd1a598efd35246b746a75dcfbff56c0..518cbc44ec468b4e62de6d59db8375f5b9775224 100644 (file)
@@ -1153,7 +1153,7 @@ int R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
        if (ix2 <= ix1 || iy2 <= iy1)
                return true;
        // set up the scissor rectangle
-       GL_Scissor(ix1, iy1, ix2 - ix1, iy2 - iy1);
+       GL_Scissor(ix1, vid.realheight - iy2, ix2 - ix1, iy2 - iy1);
        //qglScissor(ix1, iy1, ix2 - ix1, iy2 - iy1);
        //qglEnable(GL_SCISSOR_TEST);
        c_rt_scissored++;
@@ -1863,6 +1863,7 @@ vec3_t r_editlights_cursorlocation;
 
 static int lightpvsbytes;
 static qbyte lightpvs[(MAX_MAP_LEAFS + 7)/ 8];
+static qbyte lightfullpvs[(MAX_MAP_LEAFS + 7)/ 8];
 
 typedef struct cubemapinfo_s
 {
@@ -2037,18 +2038,34 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
        e->meshchain_light = Mod_ShadowMesh_Begin(r_shadow_mempool, 32768, 32768, NULL, NULL, NULL, true, false, true);
        if (cl.worldmodel)
        {
+               lightpvsbytes = cl.worldmodel->brush.FatPVS(cl.worldmodel, origin, 0, lightfullpvs, sizeof(lightfullpvs));
+               memset(lightpvs, 0, lightpvsbytes);
                if (cl.worldmodel->brushq3.num_leafs)
                {
                        q3mleaf_t *leaf;
                        q3mface_t *face;
-                       lightpvsbytes = cl.worldmodel->brush.FatPVS(cl.worldmodel, origin, 0, lightpvs, sizeof(lightpvs));
+
+                       // make a pvs that only includes things within the box
+                       for (i = 0, leaf = cl.worldmodel->brushq3.data_leafs;i < cl.worldmodel->brushq3.num_leafs;i++, leaf++)
+                               if (CHECKPVSBIT(lightfullpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
+                                       SETPVSBIT(lightpvs, leaf->clusterindex);
+
+                       // make a cluster list for fast visibility checking during rendering
+                       for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                               if (CHECKPVSBIT(lightpvs, i))
+                                       e->numclusters++;
+                       e->clusterindices = Mem_Alloc(r_shadow_mempool, e->numclusters * sizeof(int));
+                       for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                               if (CHECKPVSBIT(lightpvs, i))
+                                       e->clusterindices[e->numclusters++] = i;
+
                        VectorCopy(e->origin, e->mins);
                        VectorCopy(e->origin, e->maxs);
                        for (i = 0, face = cl.worldmodel->brushq3.data_thismodel->firstface;i < cl.worldmodel->brushq3.data_thismodel->numfaces;i++, face++)
                                face->lighttemp_castshadow = false;
                        for (i = 0, leaf = cl.worldmodel->brushq3.data_leafs;i < cl.worldmodel->brushq3.num_leafs;i++, leaf++)
                        {
-                               if ((leaf->clusterindex < 0 || lightpvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7))) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
+                               if (CHECKPVSBIT(lightpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
                                {
                                        for (k = 0;k < 3;k++)
                                        {
@@ -2081,7 +2098,7 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
                                }
                        }
                }
-               else if (cl.worldmodel->brushq1.numleafs)
+               else if (cl.worldmodel->brushq1.num_leafs)
                {
                        mleaf_t *leaf;
                        msurface_t *surf;
@@ -2097,15 +2114,17 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
                                qbyte *byteleafpvs;
                                qbyte *bytesurfacepvs;
 
-                               byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numleafs);
+                               byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.num_leafs);
                                bytesurfacepvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numsurfaces);
 
                                Portal_Visibility(cl.worldmodel, e->origin, byteleafpvs, bytesurfacepvs, NULL, 0, true, mins, maxs, e->mins, e->maxs);
 
-                               for (i = 0, leaf = cl.worldmodel->brushq1.leafs;i < cl.worldmodel->brushq1.numleafs;i++, leaf++)
+                               // make a pvs that only includes things within the box
+                               for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
                                {
                                        if (byteleafpvs[i] && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
                                        {
+                                               SETPVSBIT(lightpvs, leaf->clusterindex);
                                                for (k = 0;k < 3;k++)
                                                {
                                                        if (e->mins[k] > leaf->mins[k]) e->mins[k] = leaf->mins[k];
@@ -2113,21 +2132,31 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
                                                }
                                        }
                                }
-
+       
                                for (i = 0, surf = cl.worldmodel->brushq1.surfaces;i < cl.worldmodel->brushq1.numsurfaces;i++, surf++)
                                        if (bytesurfacepvs[i] && BoxesOverlap(surf->poly_mins, surf->poly_maxs, mins, maxs))
                                                surf->lighttemp_castshadow = true;
 
                                Mem_Free(byteleafpvs);
                                Mem_Free(bytesurfacepvs);
+       
+                               // make a cluster list for fast visibility checking during rendering
+                               for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                                       if (CHECKPVSBIT(lightpvs, i))
+                                               e->numclusters++;
+                               e->clusterindices = Mem_Alloc(r_shadow_mempool, e->numclusters * sizeof(int));
+                               for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                                       if (CHECKPVSBIT(lightpvs, i))
+                                               e->clusterindices[e->numclusters++] = i;
                        }
                        else
                        {
-                               lightpvsbytes = cl.worldmodel->brush.FatPVS(cl.worldmodel, origin, 0, lightpvs, sizeof(lightpvs));
-                               for (i = 0, leaf = cl.worldmodel->brushq1.leafs + 1;i < cl.worldmodel->brushq1.visleafs;i++, leaf++)
+                               for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
                                {
-                                       if (lightpvs[i >> 3] & (1 << (i & 7)) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
+                                       if (CHECKPVSBIT(lightfullpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
                                        {
+                                               // make a pvs that only includes things within the box
+                                               SETPVSBIT(lightpvs, leaf->clusterindex);
                                                for (k = 0;k < 3;k++)
                                                {
                                                        if (e->mins[k] > leaf->mins[k]) e->mins[k] = leaf->mins[k];
@@ -2141,6 +2170,20 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
                                                }
                                        }
                                }
+
+                               // make a pvs that only includes things within the box
+                               for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
+                                       if (CHECKPVSBIT(lightfullpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
+                                               SETPVSBIT(lightpvs, leaf->clusterindex);
+
+                               // make a cluster list for fast visibility checking during rendering
+                               for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                                       if (CHECKPVSBIT(lightpvs, i))
+                                               e->numclusters++;
+                               e->clusterindices = Mem_Alloc(r_shadow_mempool, e->numclusters * sizeof(int));
+                               for (i = 0, e->numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
+                                       if (CHECKPVSBIT(lightpvs, i))
+                                               e->clusterindices[e->numclusters++] = i;
                        }
 
                        // add surfaces to shadow casting mesh and light mesh
@@ -2208,7 +2251,7 @@ void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t ra
        if (e->meshchain_light)
                for (mesh = e->meshchain_light;mesh;mesh = mesh->next)
                        l += mesh->numtriangles;
-       Con_Printf("static light built: %f %f %f : %f %f %f box, %i shadow volume triangles, %i light triangles\n", e->mins[0], e->mins[1], e->mins[2], e->maxs[0], e->maxs[1], e->maxs[2], k, l);
+       Con_DPrintf("static light built: %f %f %f : %f %f %f box, %i shadow volume triangles, %i light triangles\n", e->mins[0], e->mins[1], e->mins[2], e->maxs[0], e->maxs[1], e->maxs[2], k, l);
 }
 
 void R_Shadow_FreeWorldLight(worldlight_t *light)
@@ -2456,7 +2499,7 @@ void R_Shadow_LoadLightsFile(void)
 
 void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void)
 {
-       int entnum, style, islight;
+       int entnum, style, islight, skin, pflags;
        char key[256], value[1024];
        float origin[3], radius, color[3], light, fadescale, lightscale, originhack[3], overridecolor[3];
        const char *data;
@@ -2479,6 +2522,8 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void)
                fadescale = 1;
                lightscale = 1;
                style = 0;
+               skin = 0;
+               pflags = 0;
                islight = false;
                while (1)
                {
@@ -2584,6 +2629,10 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void)
                                if (!strcmp("fade", key))
                                        fadescale = atof(value);
                        }
+                       else if (!strcmp("skin", key))
+                               skin = (int)atof(value);
+                       else if (!strcmp("pflags", key))
+                               pflags = (int)atof(value);
                }
                if (light <= 0 && islight)
                        light = 300;
@@ -2598,7 +2647,7 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void)
                VectorScale(color, light, color);
                VectorAdd(origin, originhack, origin);
                if (radius >= 15)
-                       R_Shadow_NewWorldLight(origin, vec3_origin, color, radius, 0, style, true, NULL);
+                       R_Shadow_NewWorldLight(origin, vec3_origin, color, radius, !!(pflags & 2), style, !(pflags & 1), skin >= 16 ? va("cubemaps/%i", skin) : NULL);
        }
 }