From b35cb8eb7eee631451e1d45a90efb64b7dda8264 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 20 Aug 2020 12:08:46 -0600 Subject: [PATCH] light: fixes for bjptools skip faces (which have no associated model) --- include/light/light.hh | 3 +++ light/light.cc | 2 +- light/ltface.cc | 6 +++++- light/trace_embree.cc | 8 +++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index da7633eb..605b12c6 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -420,6 +420,9 @@ void FixupGlobalSettings(void); void GetFileSpace(byte **lightdata, byte **colordata, byte **deluxdata, int size); void GetFileSpace_PreserveOffsetInBsp(byte **lightdata, byte **colordata, byte **deluxdata, int lightofs); const modelinfo_t *ModelInfoForModel(const mbsp_t *bsp, int modelnum); +/** + * returs nullptr for "skip" faces + */ const modelinfo_t *ModelInfoForFace(const mbsp_t *bsp, int facenum); //bool Leaf_HasSky(const mbsp_t *bsp, const mleaf_t *leaf); //mxd. Missing definition int light_main(int argc, const char **argv); diff --git a/light/light.cc b/light/light.cc index 817bed5a..48cbaa14 100644 --- a/light/light.cc +++ b/light/light.cc @@ -652,7 +652,7 @@ FindDebugFace(const mbsp_t *bsp) dump_facenum = facenum; const modelinfo_t *mi = ModelInfoForFace(bsp, facenum); - const int modelnum = (mi->model - bsp->dmodels); + const int modelnum = mi ? (mi->model - bsp->dmodels) : -1; const char *texname = Face_TextureName(bsp, f); diff --git a/light/ltface.cc b/light/ltface.cc index 6d6a72af..55a4ecdc 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -639,7 +639,11 @@ PositionSamplePointOnFace(const mbsp_t *bsp, } const modelinfo_t *mi = ModelInfoForFace(bsp, Face_GetNum(bsp, face)); - + if (mi == nullptr) { + // missing model ("skip" faces) don't get lighting + return position_t(point); + } + // Get the point normal qvec3f pointNormal; if (phongShaded) { diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 839cdd94..1939e188 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -117,6 +117,7 @@ CreateGeometry(const mbsp_t *bsp, RTCScene scene, const std::vectornumedges < 3) continue; + // NOTE: can be null for "skip" faces const modelinfo_t *modelinfo = ModelInfoForFace(bsp, Face_GetNum(bsp, face)); for (int j = 2; j < face->numedges; j++) { @@ -289,7 +290,12 @@ Embree_FilterFuncN(int* valid, const modelinfo_t *source_modelinfo = rsi->self; const modelinfo_t *hit_modelinfo = Embree_LookupModelinfo(geomID, primID); - Q_assert(hit_modelinfo != nullptr); + if (!hit_modelinfo) { + // we hit a "skip" face with no associated model + // reject hit (???) + valid[i] = INVALID; + continue; + } if (hit_modelinfo->shadowworldonly.boolValue()) { // we hit "_shadowworldonly" "1" geometry. Ignore the hit unless we are from world.