From cc143f0750869f06bef86f11dcbe1c9bef7105f8 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 8 May 2014 03:06:11 +0000 Subject: [PATCH] Reworked r_useportalculling to use expanded portal bboxes based on r_nearclip, this resolves an issue where a portal could lie entirely behind the nearclip plane of the frustum, but still need to be recursed. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12071 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rsurf.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/gl_rsurf.c b/gl_rsurf.c index 17b183d2..38a92892 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -524,6 +524,8 @@ void R_View_WorldVisibility(qboolean forcenovis) int leafstackpos; mportal_t *p; mleaf_t *leafstack[8192]; + vec3_t cullmins, cullmaxs; + float cullbias = r_nearclip.value * 2.0f; // the nearclip plane can easily end up culling portals in certain perfectly-aligned views, causing view blackouts // simple-frustum portal method: // follows portals leading outward from viewleaf, does not venture // offscreen or into leafs that are not visible, faster than @@ -548,20 +550,27 @@ void R_View_WorldVisibility(qboolean forcenovis) r_refdef.viewcache.world_surfacevisible[*mark] = true; // follow portals into other leafs // the checks are: - // if viewer is behind portal (portal faces outward into the scene) - // and the portal polygon's bounding box is on the screen - // and the leaf has not been visited yet + // the leaf has not been visited yet // and the leaf is visible in the pvs - // (the first two checks won't cause as many cache misses as the leaf checks) + // the portal polygon's bounding box is on the screen for (p = leaf->portals;p;p = p->next) { r_refdef.stats[r_stat_world_portals]++; - if (DotProduct(r_refdef.view.origin, p->plane.normal) < (p->plane.dist + 1) - && !r_refdef.viewcache.world_leafvisible[p->past - model->brush.data_leafs] - && CHECKPVSBIT(r_refdef.viewcache.world_pvsbits, p->past->clusterindex) - && !R_CullBox(p->mins, p->maxs) - && leafstackpos < (int)(sizeof(leafstack) / sizeof(leafstack[0]))) - leafstack[leafstackpos++] = p->past; + if (r_refdef.viewcache.world_leafvisible[p->past - model->brush.data_leafs]) + continue; + if (!CHECKPVSBIT(r_refdef.viewcache.world_pvsbits, p->past->clusterindex)) + continue; + cullmins[0] = p->mins[0] - cullbias; + cullmins[1] = p->mins[1] - cullbias; + cullmins[2] = p->mins[2] - cullbias; + cullmaxs[0] = p->maxs[0] + cullbias; + cullmaxs[1] = p->maxs[1] + cullbias; + cullmaxs[2] = p->maxs[2] + cullbias; + if (R_CullBox(cullmins, cullmaxs)) + continue; + if (leafstackpos >= (int)(sizeof(leafstack) / sizeof(leafstack[0]))) + break; + leafstack[leafstackpos++] = p->past; } } } -- 2.39.2