From 28b034a17233a85a42ed7706d8f1e0385ac490c1 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 10 Aug 2016 00:49:41 -0600 Subject: [PATCH] light: drop visdata support, no longer needed --- include/light/light.hh | 8 -- light/light.cc | 66 ---------------- light/ltface.cc | 169 ----------------------------------------- 3 files changed, 243 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index ae2b79fb..1de3c42e 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -111,13 +111,6 @@ typedef struct { */ vec_t *occlusion; // malloc'ed array of numpoints - /* - pvs for the entire light surface. generated by ORing together - the pvs at each of the sample points - */ - byte *pvs; - bool skyvisible; - /* for sphere culling */ vec3_t origin; vec_t radius; @@ -643,7 +636,6 @@ extern int write_luxfile; extern qboolean onlyents; extern qboolean scaledonly; extern uint32_t *extended_texinfo_flags; -extern qboolean novis; extern qboolean novisapprox; extern bool nolights; diff --git a/light/light.cc b/light/light.cc index 156a73e3..d3181e22 100644 --- a/light/light.cc +++ b/light/light.cc @@ -127,7 +127,6 @@ int oversample = 1; int write_litfile = 0; /* 0 for none, 1 for .lit, 2 for bspx, 3 for both */ int write_luxfile = 0; /* 0 for none, 1 for .lux, 2 for bspx, 3 for both */ qboolean onlyents = false; -qboolean novis = false; /* if true, don't use vis data */ qboolean novisapprox = false; bool nolights = false; backend_t rtbackend = backend_embree; @@ -1078,67 +1077,6 @@ ExportObj(const char *filename, const bsp2_t *bsp) //obj -vector> faceleafs; -vector leafhassky; - -// index some stuff from the bsp -static void -BuildPvsIndex(const bsp2_t *bsp) -{ - if (bsp->visdatasize != 0) { - if (novis) { - logprint("skipping visdata optimization because of -novis\n"); - } else { - logprint("using visdata optimization\n"); - } - } - - // build leafsForFace - faceleafs.resize(bsp->numfaces); - for (int i = 0; i < bsp->numleafs; i++) { - const bsp2_dleaf_t *leaf = &bsp->dleafs[i]; - for (int k = 0; k < leaf->nummarksurfaces; k++) { - const int facenum = bsp->dmarksurfaces[leaf->firstmarksurface + k]; - faceleafs.at(facenum).push_back(leaf); - } - } - - // build leafhassky - leafhassky.resize(bsp->numleafs, false); - for (int i = 0; i < bsp->numleafs; i++) { - const bsp2_dleaf_t *leaf = &bsp->dleafs[i]; - - // 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)) { - leafhassky.at(i) = true; - break; - } - } - } -} - -bool Leaf_HasSky(const bsp2_t *bsp, const bsp2_dleaf_t *leaf) -{ - const int leafnum = leaf - bsp->dleafs; - return leafhassky.at(leafnum); -} - -static const bsp2_dleaf_t ** -Face_CopyLeafList(const bsp2_t *bsp, const bsp2_dface_t *face) -{ - const int facenum = face - bsp->dfaces; - auto &leafs = faceleafs.at(facenum); - - const bsp2_dleaf_t **result = (const bsp2_dleaf_t **) calloc(leafs.size() + 1, sizeof(const bsp2_dleaf_t *)); - for (int i = 0; idmodels[0].visleafs + 7) / 8; -} - -// from DarkPlaces -static void Mod_Q1BSP_DecompressVis(const unsigned char *in, const unsigned char *inend, unsigned char *out, unsigned char *outend) -{ - int c; - unsigned char *outstart = out; - while (out < outend) - { - if (in == inend) - { - logprint("Mod_Q1BSP_DecompressVis: input underrun (decompressed %i of %i output bytes)\n", (int)(out - outstart), (int)(outend - outstart)); - return; - } - c = *in++; - if (c) - *out++ = c; - else - { - if (in == inend) - { - logprint("Mod_Q1BSP_DecompressVis: input underrun (during zero-run) (decompressed %i of %i output bytes)\n", (int)(out - outstart), (int)(outend - outstart)); - return; - } - for (c = *in++;c > 0;c--) - { - if (out == outend) - { - logprint("Mod_Q1BSP_DecompressVis: output overrun (decompressed %i of %i output bytes)\n", (int)(out - outstart), (int)(outend - outstart)); - return; - } - *out++ = 0; - } - } - } -} - -static bool -Mod_LeafPvs(const bsp2_t *bsp, const bsp2_dleaf_t *leaf, byte *out) -{ - const int num_pvsclusterbytes = DecompressedVisSize(bsp); - - // init to all visible - memset(out, 0xFF, num_pvsclusterbytes); - - // this is confusing.. "visleaf numbers" are the leaf number minus 1. - // they also don't go as high, bsp->dmodels[0].visleafs instead of bsp->numleafs - const int leafnum = (leaf - bsp->dleafs); - const int visleaf = leafnum - 1; - if (visleaf < 0 || visleaf >= bsp->dmodels[0].visleafs) - return false; - - if (leaf->visofs < 0) - return false; - - if (leaf->visofs >= bsp->visdatasize) { - logprint("Mod_LeafPvs: invalid visofs for leaf %d\n", leafnum); - return false; - } - - Mod_Q1BSP_DecompressVis(bsp->dvisdata + leaf->visofs, - bsp->dvisdata + bsp->visdatasize, - out, - out + num_pvsclusterbytes); - return true; -} - -// returns true if pvs can see leaf -static bool -Pvs_LeafVisible(const bsp2_t *bsp, const byte *pvs, const bsp2_dleaf_t *leaf) -{ - const int leafnum = (leaf - bsp->dleafs); - const int visleaf = leafnum - 1; - if (visleaf < 0 || visleaf >= bsp->dmodels[0].visleafs) - return false; - - return !!(pvs[visleaf>>3] & (1<<(visleaf&7))); -} - -static void -CalcPvs(const bsp2_t *bsp, lightsurf_t *lightsurf) -{ - const int pvssize = DecompressedVisSize(bsp); - const bsp2_dleaf_t *lastleaf = NULL; - - // set defaults - lightsurf->pvs = NULL; - lightsurf->skyvisible = true; - - if (!bsp->visdatasize) return; - - // set lightsurf->pvs - byte *pointpvs = (byte *) calloc(pvssize, 1); - lightsurf->pvs = (byte *) calloc(pvssize, 1); - - for (int i = 0; i < lightsurf->numpoints; i++) { - const bsp2_dleaf_t *leaf = Light_PointInLeaf (bsp, lightsurf->points[i]); - - /* most/all of the surface points are probably in the same leaf */ - if (leaf == lastleaf) - continue; - - lastleaf = leaf; - - /* copy the pvs for this leaf into pointpvs */ - Mod_LeafPvs(bsp, leaf, pointpvs); - - /* merge the pvs for this sample point into lightsurf->pvs */ - for (int j=0; jpvs[j] |= pointpvs[j]; - } - } - - free(pointpvs); pointpvs = NULL; - - // 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 - if (Leaf_HasSky(bsp, leaf)) { - lightsurf->skyvisible = true; - break; - } - } - } -} - static void Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face, const bsp2_t *bsp, lightsurf_t *lightsurf, facesup_t *facesup) @@ -896,9 +763,6 @@ Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face, /* Allocate occlusion array */ lightsurf->occlusion = (float *) calloc(lightsurf->numpoints, sizeof(float)); - - /* Setup vis data */ - CalcPvs(bsp, lightsurf); lightsurf->stream = MakeRayStream(lightsurf->numpoints); } @@ -1266,25 +1130,6 @@ 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 byte *pvs, const bsp2_dleaf_t *entleaf) -{ - if (novis) return false; - if (pvs == NULL) return false; - if (entleaf == NULL) return false; - - if (entleaf->contents == CONTENTS_SOLID - || entleaf->contents == CONTENTS_SKY) { - return false; - } - - if (Pvs_LeafVisible(bsp, pvs, entleaf)) { - return false; - } - - return true; -} - // FIXME: factor out / merge with LightFace void GetDirectLighting(raystream_t *rs, const vec3_t origin, const vec3_t normal, vec3_t colorout) @@ -1366,11 +1211,6 @@ LightFace_Entity(const bsp2_t *bsp, const modelinfo_t *modelinfo = lightsurf->modelinfo; const plane_t *plane = &lightsurf->plane; - /* vis cull */ - if (VisCullEntity(bsp, lightsurf->pvs, entity->leaf)) { - return; - } - const float planedist = DotProduct(*entity->origin.vec3Value(), plane->normal) - plane->dist; /* don't bother with lights behind the surface. @@ -1509,11 +1349,6 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmap_t *lightm const modelinfo_t *modelinfo = lightsurf->modelinfo; const plane_t *plane = &lightsurf->plane; - /* 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 && !lightsurf->curved && !lightsurf->twosided) { return; @@ -1835,9 +1670,6 @@ LightFace_Bounce(const bsp2_t *bsp, const bsp2_dface_t *face, const lightsurf_t bool hit = false; for (const bouncelight_t &vpl : BounceLights()) { - if (VisCullEntity(bsp, lightsurf->pvs, vpl.leaf)) - continue; - if (BounceLight_SphereCull(bsp, &vpl, lightsurf)) continue; @@ -2335,7 +2167,6 @@ void LightFaceShutdown(struct ltface_ctx *ctx) free(ctx->lightsurf->normals); free(ctx->lightsurf->occlusion); free(ctx->lightsurf->occluded); - free(ctx->lightsurf->pvs); delete ctx->lightsurf->stream;