From 2b9253f2a56c8e33c7ac33c794c1f03acc91048c Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 8 Mar 2005 14:02:21 +0000 Subject: [PATCH] added r_worldleafvisible flags array for more exact visibility checking (VIS_CullBox does not use this yet however, only rtlights do) 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 | 9 --------- gl_rsurf.c | 22 +++++++++++++++++----- r_shadow.c | 2 +- render.h | 10 ++++++++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index b73e5fbc..72dd0228 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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 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; @@ -799,8 +792,6 @@ void R_RenderScene(void) 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"); diff --git a/gl_rsurf.c b/gl_rsurf.c index 797a8ec2..7375ebf6 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -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"}; +// 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) @@ -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 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_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 @@ -1350,6 +1363,7 @@ void R_WorldVisibility(void) 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; @@ -1361,7 +1375,6 @@ void R_WorldVisibility(void) 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 @@ -1369,12 +1382,11 @@ void R_WorldVisibility(void) // 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]; - 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++) @@ -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) - 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; } } diff --git a/r_shadow.c b/r_shadow.c index 31615386..8a82f064 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2727,7 +2727,7 @@ void R_DrawRTLight(rtlight_t *rtlight, int visiblevolumes) if (numclusters) { for (i = 0;i < numclusters;i++) - if (CHECKPVSBIT(r_pvsbits, clusterlist[i])) + if (r_worldleafvisible[clusterlist[i]]) break; if (i == numclusters) return; diff --git a/render.h b/render.h index 692f1ebf..f0169a8f 100644 --- 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 -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; -- 2.39.2