light: clean up LightFace() function
This commit is contained in:
parent
d30c970d8b
commit
71a3dd769a
|
|
@ -150,15 +150,6 @@ typedef struct {
|
|||
lightmapdict_t lightmapsByStyle;
|
||||
} lightsurf_t;
|
||||
|
||||
struct ltface_ctx
|
||||
{
|
||||
const bsp2_t *bsp;
|
||||
lightsurf_t *lightsurf;
|
||||
const globalconfig_t *cfg;
|
||||
};
|
||||
|
||||
extern struct ltface_ctx *ltface_ctxs;
|
||||
|
||||
/* debug */
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ vec_t GetLightValue(const globalconfig_t &cfg, const light_t *entity, vec_t dist
|
|||
void GetDirectLighting(const globalconfig_t &cfg, raystream_t *rs, const vec3_t origin, const vec3_t normal, vec3_t colorout);
|
||||
void SetupDirt(globalconfig_t &cfg);
|
||||
float DirtAtPoint(const globalconfig_t &cfg, raystream_t *rs, const vec3_t point, const vec3_t normal, const dmodel_t *selfshadow);
|
||||
void LightFaceInit(const bsp2_t *bsp, struct ltface_ctx *ctx);
|
||||
void LightFaceShutdown(struct ltface_ctx *ctx);
|
||||
void LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, struct ltface_ctx *ctx);
|
||||
void LightFace(const bsp2_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg);
|
||||
|
||||
#endif /* __LIGHT_LTFACE_H__ */
|
||||
|
|
|
|||
|
|
@ -99,8 +99,6 @@ uint64_t *extended_texinfo_flags = NULL;
|
|||
|
||||
char mapfilename[1024];
|
||||
|
||||
struct ltface_ctx *ltface_ctxs;
|
||||
|
||||
int dump_facenum = -1;
|
||||
bool dump_face;
|
||||
vec3_t dump_face_point = {0,0,0};
|
||||
|
|
@ -228,10 +226,7 @@ const modelinfo_t *ModelInfoForFace(const bsp2_t *bsp, int facenum)
|
|||
static void *
|
||||
LightThread(void *arg)
|
||||
{
|
||||
int facenum, i;
|
||||
const bsp2_t *bsp = (const bsp2_t *)arg;
|
||||
const modelinfo_t *face_modelinfo;
|
||||
struct ltface_ctx *ctx;
|
||||
|
||||
#ifdef HAVE_EMBREE
|
||||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
||||
|
|
@ -239,45 +234,40 @@ LightThread(void *arg)
|
|||
#endif
|
||||
|
||||
while (1) {
|
||||
facenum = GetThreadWork();
|
||||
const int facenum = GetThreadWork();
|
||||
if (facenum == -1)
|
||||
break;
|
||||
|
||||
ctx = <face_ctxs[facenum];
|
||||
|
||||
LightFaceInit(bsp, ctx);
|
||||
ctx->cfg = &cfg_static;
|
||||
bsp2_dface_t *f = &bsp->dfaces[facenum];
|
||||
|
||||
/* Find the correct model offset */
|
||||
face_modelinfo = ModelInfoForFace(bsp, facenum);
|
||||
const modelinfo_t *face_modelinfo = ModelInfoForFace(bsp, facenum);
|
||||
if (face_modelinfo == NULL) {
|
||||
// ericw -- silenced this warning becasue is causes spam when "skip" faces are used
|
||||
//logprint("warning: no model has face %d\n", facenum);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!faces_sup)
|
||||
LightFace(bsp->dfaces + facenum, NULL, face_modelinfo, ctx);
|
||||
LightFace(bsp, f, nullptr, cfg_static);
|
||||
else if (scaledonly)
|
||||
{
|
||||
bsp->dfaces[facenum].lightofs = -1;
|
||||
bsp->dfaces[facenum].styles[0] = 255;
|
||||
LightFace(bsp->dfaces + facenum, faces_sup + facenum, face_modelinfo, ctx);
|
||||
f->lightofs = -1;
|
||||
f->styles[0] = 255;
|
||||
LightFace(bsp, f, faces_sup + facenum, cfg_static);
|
||||
}
|
||||
else if (faces_sup[facenum].lmscale == face_modelinfo->lightmapscale)
|
||||
{
|
||||
LightFace(bsp->dfaces + facenum, NULL, face_modelinfo, ctx);
|
||||
faces_sup[facenum].lightofs = bsp->dfaces[facenum].lightofs;
|
||||
for (i = 0; i < MAXLIGHTMAPS; i++)
|
||||
faces_sup[facenum].styles[i] = bsp->dfaces[facenum].styles[i];
|
||||
LightFace(bsp, f, nullptr, cfg_static);
|
||||
faces_sup[facenum].lightofs = f->lightofs;
|
||||
for (int i = 0; i < MAXLIGHTMAPS; i++)
|
||||
faces_sup[facenum].styles[i] = f->styles[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
LightFace(bsp->dfaces + facenum, NULL, face_modelinfo, ctx);
|
||||
LightFace(bsp->dfaces + facenum, faces_sup + facenum, face_modelinfo, ctx);
|
||||
LightFace(bsp, f, nullptr, cfg_static);
|
||||
LightFace(bsp, f, faces_sup + facenum, cfg_static);
|
||||
}
|
||||
|
||||
LightFaceShutdown(ctx);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -419,9 +409,6 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale)
|
|||
|
||||
EdgeToFaceMap = MakeEdgeToFaceMap(bsp);
|
||||
CalcualateVertexNormals(bsp);
|
||||
|
||||
/* ericw -- alloc memory */
|
||||
ltface_ctxs = (struct ltface_ctx *)calloc(bsp->numfaces, sizeof(struct ltface_ctx));
|
||||
|
||||
#if 0
|
||||
lightbatchthread_info_t info;
|
||||
|
|
|
|||
|
|
@ -2330,30 +2330,20 @@ WriteLightmaps(const bsp2_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const
|
|||
}
|
||||
}
|
||||
|
||||
void LightFaceInit(const bsp2_t *bsp, struct ltface_ctx *ctx)
|
||||
static void LightFaceShutdown(lightsurf_t *lightsurf)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->bsp = bsp;
|
||||
}
|
||||
|
||||
void LightFaceShutdown(struct ltface_ctx *ctx)
|
||||
{
|
||||
if (!ctx->lightsurf)
|
||||
return;
|
||||
|
||||
for (auto &lm : ctx->lightsurf->lightmapsByStyle) {
|
||||
for (auto &lm : lightsurf->lightmapsByStyle) {
|
||||
free(lm.samples);
|
||||
}
|
||||
|
||||
free(ctx->lightsurf->points);
|
||||
free(ctx->lightsurf->normals);
|
||||
free(ctx->lightsurf->occlusion);
|
||||
free(ctx->lightsurf->occluded);
|
||||
free(lightsurf->points);
|
||||
free(lightsurf->normals);
|
||||
free(lightsurf->occlusion);
|
||||
free(lightsurf->occluded);
|
||||
|
||||
delete ctx->lightsurf->stream;
|
||||
delete lightsurf->stream;
|
||||
|
||||
delete ctx->lightsurf;
|
||||
delete lightsurf;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -2362,9 +2352,14 @@ void LightFaceShutdown(struct ltface_ctx *ctx)
|
|||
* ============
|
||||
*/
|
||||
void
|
||||
LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, struct ltface_ctx *ctx)
|
||||
LightFace(const bsp2_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg)
|
||||
{
|
||||
const bsp2_t *bsp = ctx->bsp;
|
||||
/* Find the correct model offset */
|
||||
const modelinfo_t *modelinfo = ModelInfoForFace(bsp, Face_GetNum(bsp, face));
|
||||
if (modelinfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
|
||||
/* One extra lightmap is allocated to simplify handling overflow */
|
||||
|
|
@ -2394,11 +2389,8 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
return;
|
||||
|
||||
/* all good, this face is going to be lightmapped. */
|
||||
ctx->lightsurf = new lightsurf_t {};
|
||||
lightsurf_t *lightsurf = ctx->lightsurf;
|
||||
lightsurf->cfg = ctx->cfg;
|
||||
|
||||
const globalconfig_t &cfg = *lightsurf->cfg;
|
||||
lightsurf_t *lightsurf = new lightsurf_t {};
|
||||
lightsurf->cfg = &cfg;
|
||||
|
||||
/* if liquid doesn't have the TEX_SPECIAL flag set, the map was qbsp'ed with
|
||||
* lit water in mind. In that case receive light from both top and bottom.
|
||||
|
|
@ -2439,7 +2431,7 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
LightFace_Sky (&sun, lightsurf, lightmaps);
|
||||
|
||||
/* add indirect lighting */
|
||||
LightFace_Bounce(ctx->bsp, face, lightsurf, lightmaps);
|
||||
LightFace_Bounce(bsp, face, lightsurf, lightmaps);
|
||||
}
|
||||
|
||||
/* minlight - Use the greater of global or model minlight. */
|
||||
|
|
@ -2471,7 +2463,7 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
/* bounce debug */
|
||||
// TODO: add a BounceDebug function that clear the lightmap to make the code more clear
|
||||
if (debugmode == debugmode_bounce)
|
||||
LightFace_Bounce(ctx->bsp, face, lightsurf, lightmaps);
|
||||
LightFace_Bounce(bsp, face, lightsurf, lightmaps);
|
||||
|
||||
/* replace lightmaps with AO for debugging */
|
||||
if (debugmode == debugmode_dirt)
|
||||
|
|
@ -2494,4 +2486,6 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
}
|
||||
|
||||
WriteLightmaps(bsp, face, facesup, lightsurf, lightmaps);
|
||||
|
||||
LightFaceShutdown(lightsurf);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue