light: use vis acceleration for bounce lights

This commit is contained in:
Eric Wasylishen 2016-04-29 11:27:02 -06:00
parent 7f31e6d4fd
commit 2bca34265c
3 changed files with 18 additions and 12 deletions

View File

@ -300,7 +300,7 @@ extern qboolean phongDebug;
extern char mapfilename[1024]; 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 void
PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp); 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) */ /* PVS index (light.cc) */
bool Leaf_HasSky(const bsp2_t *bsp, const bsp2_dleaf_t *leaf); 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 #ifdef __cplusplus
} }

View File

@ -763,6 +763,7 @@ public:
vec3_t color; vec3_t color;
vec3_t surfnormal; vec3_t surfnormal;
vec_t area; vec_t area;
const bsp2_dleaf_t *leaf;
}; };
std::vector<light_t> radlights; std::vector<light_t> radlights;
@ -984,6 +985,7 @@ void MakeBounceLights (const bsp2_t *bsp)
VectorCopy(patch->directlight, l.color); VectorCopy(patch->directlight, l.color);
VectorCopy(patch->plane.normal, l.surfnormal); VectorCopy(patch->plane.normal, l.surfnormal);
l.area = WindingArea(patch->w); l.area = WindingArea(patch->w);
l.leaf = Light_PointInLeaf(bsp, l.pos);
radlights.push_back(l); radlights.push_back(l);
} }
} }
@ -995,12 +997,15 @@ void MakeBounceLights (const bsp2_t *bsp)
// returns color in [0,255] // 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); VectorSet(colorout, 0, 0, 0);
// sample vpls // sample vpls
for (const auto &vpl : radlights) { for (const auto &vpl : radlights) {
if (VisCullEntity(bsp, pvs, vpl.leaf))
continue;
vec3_t dir; vec3_t dir;
VectorSubtract(origin, vpl.pos, dir); // vpl -> sample point VectorSubtract(origin, vpl.pos, dir); // vpl -> sample point
vec_t dist = VectorNormalize(dir); vec_t dist = VectorNormalize(dir);

View File

@ -1212,18 +1212,18 @@ ProjectPointOntoPlane(const vec3_t point, const plane_t *plane, vec3_t out)
VectorMA(point, -dist, plane->normal, out); VectorMA(point, -dist, plane->normal, out);
} }
static qboolean qboolean
VisCullEntity(const bsp2_t *bsp, const lightsurf_t *lightsurf, const entity_t *entity) VisCullEntity(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *entleaf)
{ {
if (novis) return false; if (novis) return false;
if (lightsurf->pvs == NULL) return false; if (pvs == NULL) return false;
if (entity->leaf == NULL) return false; if (entleaf == NULL) return false;
if (entity->leaf->contents == CONTENTS_SOLID if (entleaf->contents == CONTENTS_SOLID
|| entity->leaf->contents == CONTENTS_SKY) || entleaf->contents == CONTENTS_SKY)
return false; return false;
if (Pvs_LeafVisible(bsp, lightsurf->pvs, entity->leaf)) if (Pvs_LeafVisible(bsp, pvs, entleaf))
return false; return false;
return true; return true;
@ -1254,7 +1254,7 @@ LightFace_Entity(const bsp2_t *bsp,
lightmap_t *lightmap; lightmap_t *lightmap;
/* vis cull */ /* vis cull */
if (VisCullEntity(bsp, lightsurf, entity)) { if (VisCullEntity(bsp, lightsurf->pvs, entity->leaf)) {
return; return;
} }
@ -1558,7 +1558,7 @@ LightFace_Bounce(const bsp2_t *bsp, const bsp2_dface_t *face, const lightsurf_t
sample = lightmap->samples; sample = lightmap->samples;
for (int i = 0; i < lightsurf->numpoints; i++, sample++) { for (int i = 0; i < lightsurf->numpoints; i++, sample++) {
vec3_t indirect = {0}; 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. */ /* Use dirt scaling on the indirect lighting. */
const vec_t dirtscale = Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf); const vec_t dirtscale = Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf);