]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added r_worldleafvisible flags array for more exact visibility checking (VIS_CullBox...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Mar 2005 14:02:21 +0000 (14:02 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 8 Mar 2005 14:02:21 +0000 (14:02 +0000)
moved r_pvsbits, r_worldsurfacevisible, r_worldleafvisible to gl_rsurf.c
migrated r_pvsbits FatPVS call from just above R_WorldVisibility to inside it

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

gl_rmain.c
gl_rsurf.c
r_shadow.c
render.h

index b73e5fbc57a96edf73876de051692c1342e230e1..72dd022858ccd5d2abc07f64b70dba0fb7ff1ed7 100644 (file)
@@ -25,13 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // used for dlight push checking and other things
 int r_framecount;
 
 // used for dlight push checking and other things
 int r_framecount;
 
-// used for visibility checking
-qbyte r_pvsbits[(MAX_MAP_LEAFS+7)>>3];
-
-// TODO: dynamic resize?  65536 seems enough because q1bsp can't have more
-// than 32768, and q3bsp compilers have more like a 4096 limit
-qbyte r_worldsurfacevisible[MAX_MAP_LEAFS];
-
 mplane_t frustum[4];
 
 matrix4x4_t r_identitymatrix;
 mplane_t frustum[4];
 
 matrix4x4_t r_identitymatrix;
@@ -799,8 +792,6 @@ void R_RenderScene(void)
 
        R_SkyStartFrame();
 
 
        R_SkyStartFrame();
 
-       if (r_refdef.worldmodel && r_refdef.worldmodel->brush.FatPVS)
-               r_refdef.worldmodel->brush.FatPVS(r_refdef.worldmodel, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
        R_WorldVisibility();
        R_TimeReport("worldvis");
 
        R_WorldVisibility();
        R_TimeReport("worldvis");
 
index 797a8ec268a27109f9483636d19781bbb126a424..7375ebf62ac3ed7579e6f31e997bd9843f3b505d 100644 (file)
@@ -40,6 +40,15 @@ cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygo
 cvar_t r_q3bsp_renderskydepth = {0, "r_q3bsp_renderskydepth", "0"};
 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
 
 cvar_t r_q3bsp_renderskydepth = {0, "r_q3bsp_renderskydepth", "0"};
 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
 
+// flag arrays used for visibility checking on world model
+// (all other entities have no per-surface/per-leaf visibility checks)
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
+qbyte r_pvsbits[(32768+7)>>3];
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
+qbyte r_worldleafvisible[32768];
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_surfaces
+qbyte r_worldsurfacevisible[262144];
+
 static int dlightdivtable[32768];
 
 static int R_IntAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surface)
 static int dlightdivtable[32768];
 
 static int R_IntAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surface)
@@ -1333,9 +1342,13 @@ void R_WorldVisibility(void)
 
        // if possible find the leaf the view origin is in
        viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
 
        // if possible find the leaf the view origin is in
        viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
+       // if possible fetch the visible cluster bits
+       if (model->brush.FatPVS)
+               model->brush.FatPVS(model, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
 
 
-       // clear the visible surface flags array
+       // clear the visible surface and leaf flags arrays
        memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
        memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
+       memset(r_worldleafvisible, 0, model->brush.num_leafs);
 
        // if the user prefers surfaceworldnode (testing?) or the viewleaf could
        // not be found, or the viewleaf is not part of the visible world
 
        // if the user prefers surfaceworldnode (testing?) or the viewleaf could
        // not be found, or the viewleaf is not part of the visible world
@@ -1350,6 +1363,7 @@ void R_WorldVisibility(void)
                        if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
                        {
                                c_leafs++;
                        if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
                        {
                                c_leafs++;
+                               r_worldleafvisible[j] = true;
                                if (leaf->numleafsurfaces)
                                        for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
                                                r_worldsurfacevisible[*mark] = true;
                                if (leaf->numleafsurfaces)
                                        for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
                                                r_worldsurfacevisible[*mark] = true;
@@ -1361,7 +1375,6 @@ void R_WorldVisibility(void)
                int leafstackpos;
                mportal_t *p;
                mleaf_t *leafstack[8192];
                int leafstackpos;
                mportal_t *p;
                mleaf_t *leafstack[8192];
-               qbyte leafvisited[32768];
                // portal method:
                // follows portals leading outward from viewleaf, does not venture
                // offscreen or into leafs that are not visible, faster than Quake's
                // portal method:
                // follows portals leading outward from viewleaf, does not venture
                // offscreen or into leafs that are not visible, faster than Quake's
@@ -1369,12 +1382,11 @@ void R_WorldVisibility(void)
                // lot of surface that pvs alone would miss
                leafstack[0] = viewleaf;
                leafstackpos = 1;
                // lot of surface that pvs alone would miss
                leafstack[0] = viewleaf;
                leafstackpos = 1;
-               memset(leafvisited, 0, model->brush.num_leafs);
                while (leafstackpos)
                {
                        c_leafs++;
                        leaf = leafstack[--leafstackpos];
                while (leafstackpos)
                {
                        c_leafs++;
                        leaf = leafstack[--leafstackpos];
-                       leafvisited[leaf - model->brush.data_leafs] = 1;
+                       r_worldleafvisible[leaf - model->brush.data_leafs] = true;
                        // mark any surfaces bounding this leaf
                        if (leaf->numleafsurfaces)
                                for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
                        // mark any surfaces bounding this leaf
                        if (leaf->numleafsurfaces)
                                for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
@@ -1387,7 +1399,7 @@ void R_WorldVisibility(void)
                        // and the leaf is visible in the pvs
                        // (the first two checks won't cause as many cache misses as the leaf checks)
                        for (p = leaf->portals;p;p = p->next)
                        // and the leaf is visible in the pvs
                        // (the first two checks won't cause as many cache misses as the leaf checks)
                        for (p = leaf->portals;p;p = p->next)
-                               if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !R_CullBox(p->mins, p->maxs) && !leafvisited[p->past - model->brush.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex))
+                               if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !R_CullBox(p->mins, p->maxs) && !r_worldleafvisible[p->past - model->brush.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex))
                                        leafstack[leafstackpos++] = p->past;
                }
        }
                                        leafstack[leafstackpos++] = p->past;
                }
        }
index 31615386f50e285e95643e472a444380aa7c25aa..8a82f06411c73ad8e78c3f84dfbf5f9a9c68680b 100644 (file)
@@ -2727,7 +2727,7 @@ void R_DrawRTLight(rtlight_t *rtlight, int visiblevolumes)
        if (numclusters)
        {
                for (i = 0;i < numclusters;i++)
        if (numclusters)
        {
                for (i = 0;i < numclusters;i++)
-                       if (CHECKPVSBIT(r_pvsbits, clusterlist[i]))
+                       if (r_worldleafvisible[clusterlist[i]])
                                break;
                if (i == numclusters)
                        return;
                                break;
                if (i == numclusters)
                        return;
index 692f1ebf1ba45a9ce1c9a5028ad93263c918120a..f0169a8fa3625ea0b4272835c80fffaf1b58b709 100644 (file)
--- a/render.h
+++ b/render.h
@@ -21,8 +21,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #ifndef RENDER_H
 #define RENDER_H
 
 #ifndef RENDER_H
 #define RENDER_H
 
-extern qbyte r_pvsbits[(MAX_MAP_LEAFS+7)>>3];
-extern qbyte r_worldsurfacevisible[MAX_MAP_LEAFS];
+// flag arrays used for visibility checking on world model
+// (all other entities have no per-surface/per-leaf visibility checks)
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
+qbyte r_pvsbits[(32768+7)>>3];
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
+qbyte r_worldleafvisible[32768];
+// TODO: dynamic resize according to r_refdef.worldmodel->brush.num_surfaces
+qbyte r_worldsurfacevisible[262144];
 
 extern matrix4x4_t r_identitymatrix;
 
 
 extern matrix4x4_t r_identitymatrix;