From 2bca34265c2c25f40a3698aa32f4965de1cb7582 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 29 Apr 2016 11:27:02 -0600 Subject: [PATCH] light: use vis acceleration for bounce lights --- include/light/light.h | 5 +++-- light/light.cc | 7 ++++++- light/ltface.c | 18 +++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/light/light.h b/include/light/light.h index cfc93392..2cf8c7e5 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -300,7 +300,7 @@ extern qboolean phongDebug; extern char mapfilename[1024]; -void GetIndirectLighting (const bsp2_t *bsp, const bsp2_dface_t *face, const vec3_t origin, const vec3_t normal, vec3_t colorout); +void GetIndirectLighting (const bsp2_t *bsp, const bsp2_dface_t *face, const byte *pvs, const vec3_t origin, const vec3_t normal, vec3_t colorout); void PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp); @@ -323,7 +323,8 @@ bool Pvs_LeafVisible(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *lea /* PVS index (light.cc) */ bool Leaf_HasSky(const bsp2_t *bsp, const bsp2_dleaf_t *leaf); -const bsp2_dleaf_t **Face_CopyLeafList(const bsp2_t *bsp, const bsp2_dface_t *face); +const bsp2_dleaf_t **Face_CopyLeafList(const bsp2_t *bsp, const bsp2_dface_t *face); +qboolean VisCullEntity(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *entleaf); #ifdef __cplusplus } diff --git a/light/light.cc b/light/light.cc index 9dc0638a..9a0c1c69 100644 --- a/light/light.cc +++ b/light/light.cc @@ -763,6 +763,7 @@ public: vec3_t color; vec3_t surfnormal; vec_t area; + const bsp2_dleaf_t *leaf; }; std::vector radlights; @@ -984,6 +985,7 @@ void MakeBounceLights (const bsp2_t *bsp) VectorCopy(patch->directlight, l.color); VectorCopy(patch->plane.normal, l.surfnormal); l.area = WindingArea(patch->w); + l.leaf = Light_PointInLeaf(bsp, l.pos); radlights.push_back(l); } } @@ -995,12 +997,15 @@ void MakeBounceLights (const bsp2_t *bsp) // returns color in [0,255] -void GetIndirectLighting (const bsp2_t *bsp, const bsp2_dface_t *face, const vec3_t origin, const vec3_t normal, vec3_t colorout) +void GetIndirectLighting (const bsp2_t *bsp, const bsp2_dface_t *face, const byte *pvs, const vec3_t origin, const vec3_t normal, vec3_t colorout) { VectorSet(colorout, 0, 0, 0); // sample vpls for (const auto &vpl : radlights) { + if (VisCullEntity(bsp, pvs, vpl.leaf)) + continue; + vec3_t dir; VectorSubtract(origin, vpl.pos, dir); // vpl -> sample point vec_t dist = VectorNormalize(dir); diff --git a/light/ltface.c b/light/ltface.c index 3674ff91..8839cb64 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -1212,18 +1212,18 @@ ProjectPointOntoPlane(const vec3_t point, const plane_t *plane, vec3_t out) VectorMA(point, -dist, plane->normal, out); } -static qboolean -VisCullEntity(const bsp2_t *bsp, const lightsurf_t *lightsurf, const entity_t *entity) +qboolean +VisCullEntity(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *entleaf) { if (novis) return false; - if (lightsurf->pvs == NULL) return false; - if (entity->leaf == NULL) return false; + if (pvs == NULL) return false; + if (entleaf == NULL) return false; - if (entity->leaf->contents == CONTENTS_SOLID - || entity->leaf->contents == CONTENTS_SKY) + if (entleaf->contents == CONTENTS_SOLID + || entleaf->contents == CONTENTS_SKY) return false; - if (Pvs_LeafVisible(bsp, lightsurf->pvs, entity->leaf)) + if (Pvs_LeafVisible(bsp, pvs, entleaf)) return false; return true; @@ -1254,7 +1254,7 @@ LightFace_Entity(const bsp2_t *bsp, lightmap_t *lightmap; /* vis cull */ - if (VisCullEntity(bsp, lightsurf, entity)) { + if (VisCullEntity(bsp, lightsurf->pvs, entity->leaf)) { return; } @@ -1558,7 +1558,7 @@ LightFace_Bounce(const bsp2_t *bsp, const bsp2_dface_t *face, const lightsurf_t sample = lightmap->samples; for (int i = 0; i < lightsurf->numpoints; i++, sample++) { vec3_t indirect = {0}; - GetIndirectLighting(bsp, face, lightsurf->points[i], lightsurf->normals[i], indirect); + GetIndirectLighting(bsp, face, lightsurf->pvs, lightsurf->points[i], lightsurf->normals[i], indirect); /* Use dirt scaling on the indirect lighting. */ const vec_t dirtscale = Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf);