From 62e513ac5939cdc12b1119e95aa67f97001430b0 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 19 Sep 2003 19:50:51 +0000 Subject: [PATCH] migrated light bounding box generation from r_shadow code to Portal_Visibility code when using r_shadow_portallight 1, I hoped this would fix bugs but it did not, still it is an optimization... git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3472 d7cf8633-e32d-0410-b094-e92efae38249 --- portals.c | 12 +++++++++++- portals.h | 2 +- r_shadow.c | 10 ++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/portals.c b/portals.c index df4cd326..ba7de15d 100644 --- a/portals.c +++ b/portals.c @@ -328,6 +328,8 @@ typedef struct portalrecursioninfo_s qbyte *leafmark; model_t *model; vec3_t eye; + float *updateleafsmins; + float *updateleafsmaxs; } portalrecursioninfo_t; @@ -388,6 +390,12 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first vec3_t center, v1, v2; tinyplane_t *newplanes; + for (i = 0;i < 3;i++) + { + if (info->updateleafsmins && info->updateleafsmins[i] > leaf->mins[i]) info->updateleafsmins[i] = leaf->mins[i]; + if (info->updateleafsmaxs && info->updateleafsmaxs[i] < leaf->maxs[i]) info->updateleafsmaxs[i] = leaf->maxs[i]; + } + if (info->leafmark) info->leafmark[leaf - info->model->brushq1.leafs] = true; @@ -462,7 +470,7 @@ void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node) } } -void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius) +void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius, float *updateleafsmins, float *updateleafsmaxs) { int i; portalrecursioninfo_t info; @@ -499,6 +507,8 @@ void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte info.model = model; VectorCopy(eye, info.eye); info.numfrustumplanes = numfrustumplanes; + info.updateleafsmins = updateleafsmins; + info.updateleafsmaxs = updateleafsmaxs; Portal_RecursiveFindLeafForFlow(&info, model->brushq1.nodes); diff --git a/portals.h b/portals.h index 25d8d3ce..92844732 100644 --- a/portals.h +++ b/portals.h @@ -4,7 +4,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpoints); int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b); -void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius); +void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius, float *updateleafsmins, float *updateleafsmaxs); #endif diff --git a/r_shadow.c b/r_shadow.c index 572997ac..160d4cca 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1754,14 +1754,15 @@ void R_Shadow_NewWorldLight(vec3_t origin, float radius, vec3_t color, int style i = CL_PointQ1Contents(e->origin); if (r_shadow_portallight.integer && i != CONTENTS_SOLID && i != CONTENTS_SKY) { - qbyte *byteleafpvs; + //qbyte *byteleafpvs; qbyte *bytesurfacepvs; - byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numleafs); + //byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numleafs); bytesurfacepvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numsurfaces); - Portal_Visibility(cl.worldmodel, e->origin, byteleafpvs, bytesurfacepvs, NULL, 0, true, RadiusFromBoundsAndOrigin(e->mins, e->maxs, e->origin)); + Portal_Visibility(cl.worldmodel, e->origin, NULL/*byteleafpvs*/, bytesurfacepvs, NULL, 0, true, RadiusFromBoundsAndOrigin(e->mins, e->maxs, e->origin), e->mins, e->maxs); + /* for (i = 0, leaf = cl.worldmodel->brushq1.leafs;i < cl.worldmodel->brushq1.numleafs;i++, leaf++) { if (byteleafpvs[i] && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs)) @@ -1773,12 +1774,13 @@ void R_Shadow_NewWorldLight(vec3_t origin, float radius, vec3_t color, int style } } } + */ 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->castshadow = castshadowcount; - Mem_Free(byteleafpvs); + //Mem_Free(byteleafpvs); Mem_Free(bytesurfacepvs); } else -- 2.39.2