light: drop visdata support, no longer needed

This commit is contained in:
Eric Wasylishen 2016-08-10 00:49:41 -06:00
parent 3d19354514
commit 28b034a172
3 changed files with 0 additions and 243 deletions

View File

@ -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;

View File

@ -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<vector<const bsp2_dleaf_t *>> faceleafs;
vector<bool> 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; i<leafs.size(); i++) {
result[i] = leafs.at(i);
}
return result;
}
static void
CheckNoDebugModeSet()
{
@ -1555,9 +1493,6 @@ main(int argc, const char **argv)
debugmode = debugmode_phong;
write_litfile |= 1;
logprint( "Phong shading debug mode enabled\n" );
} else if ( !strcmp( argv[ i ], "-novis" ) ) {
novis = true;
logprint( "Skipping use of vis data to optimize lighting\n" );
} else if ( !strcmp( argv[ i ], "-novisapprox" ) ) {
novisapprox = true;
logprint( "Skipping approximate light visibility\n" );
@ -1680,7 +1615,6 @@ main(int argc, const char **argv)
if (bspdata.version != BSP2VERSION)
ConvertBSPFormat(BSP2VERSION, &bspdata);
BuildPvsIndex(bsp);
LoadExtendedTexinfoFlags(source, bsp);
LoadEntities(bsp);

View File

@ -700,139 +700,6 @@ CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, lightsurf_t *surf,
}
}
static int
DecompressedVisSize(const bsp2_t *bsp)
{
return (bsp->dmodels[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; j<pvssize; j++) {
lightsurf->pvs[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;