From 5000f9d352abe875abd94cf9d258d04d01869cb9 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 22 Apr 2016 19:27:17 -0600 Subject: [PATCH] light: only do sunlight raytracing in leafs that can see sky --- light/ltface.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/light/ltface.c b/light/ltface.c index 3faab85d..c7bf851e 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -712,7 +712,7 @@ Pvs_LeafVisible(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *leaf) return !!(pvs[visleaf>>3] & (1<<(visleaf&7))); } -static void +void CalcPvs(const bsp2_t *bsp, lightsurf_t *lightsurf) { const int pvssize = DecompressedVisSize(bsp); @@ -764,6 +764,24 @@ CalcPvs(const bsp2_t *bsp, lightsurf_t *lightsurf) free(leafpvs); // set lightsurf->skyvisible + lightsurf->skyvisible = false; + for (int i = 0; i < bsp->numleafs; i++) { + const bsp2_dleaf_t *leaf = &bsp->dleafs[i]; + if (Pvs_LeafVisible(bsp, lightsurf->pvs, leaf)) { + // we can see this leaf, search for sky faces in it + for (int k = 0; k < leaf->nummarksurfaces; k++) { + const bsp2_dface_t *surf = &bsp->dfaces[bsp->dmarksurfaces[leaf->firstmarksurface + k]]; + const char *texname = Face_TextureName(bsp, surf); + if (!strncmp("sky", texname, 3)) { + lightsurf->skyvisible = true; + break; + } + } + } + + if (lightsurf->skyvisible) + break; // we are done + } } __attribute__((noinline)) @@ -1344,6 +1362,10 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmap_t *lightm lightmap_t *lightmap; qboolean curved = lightsurf->curved; + /* If vis data says we can't see any sky faces, skip raytracing */ + if (!lightsurf->skyvisible) + return; + /* Don't bother if surface facing away from sun */ if (DotProduct(sun->sunvec, plane->normal) < -ANGLE_EPSILON && !curved) return;