From 8ce7a682b19d9bb0cb239086b67ec4db43ae4525 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 23 Nov 2017 23:07:37 -0700 Subject: [PATCH] light: add -debugneighbours --- include/light/light.hh | 3 +- light/light.cc | 6 ++++ light/ltface.cc | 73 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/include/light/light.hh b/include/light/light.hh index 56a3aad7..597e703c 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -156,7 +156,8 @@ typedef enum { debugmode_dirt, debugmode_bounce, debugmode_bouncelights, - debugmode_debugoccluded + debugmode_debugoccluded, + debugmode_debugneighbours } debugmode_t; extern debugmode_t debugmode; diff --git a/light/light.cc b/light/light.cc index 2ed6dbc7..b089f760 100644 --- a/light/light.cc +++ b/light/light.cc @@ -1004,6 +1004,12 @@ light_main(int argc, const char **argv) } else if ( !strcmp( argv[ i ], "-debugoccluded" ) ) { CheckNoDebugModeSet(); debugmode = debugmode_debugoccluded; + } else if ( !strcmp( argv[ i ], "-debugneighbours" ) ) { + ParseVec3(dump_face_point, &i, argc, argv); + dump_face = true; + + CheckNoDebugModeSet(); + debugmode = debugmode_debugneighbours; } else if ( !strcmp( argv[ i ], "-verbose" ) ) { verbose_log = true; } else if ( !strcmp( argv[ i ], "-help" ) ) { diff --git a/light/ltface.cc b/light/ltface.cc index 7cf692f5..660092b2 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -409,6 +409,43 @@ PositionSamplePointOnFace(const mbsp_t *bsp, const qvec3f &point, const qvec3f &modelOffset); + +std::vector NeighbouringFaces_old(const mbsp_t *bsp, const bsp2_dface_t *face) +{ + std::vector result; + for (int i=0; inumedges; i++) { + const bsp2_dface_t *smoothed = Face_EdgeIndexSmoothed(bsp, face, i); + if (smoothed != nullptr + && smoothed != face) { + result.push_back(smoothed); + } + } + return result; +} + +std::vector NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face) +{ + std::set resultset; + for (int i=0; inumedges; i++) { + vec3_t p0, p1; + Face_PointAtIndex(bsp, face, i, p0); + Face_PointAtIndex(bsp, face, (i + 1) % face->numedges, p1); + + const std::vector tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]); + for (const bsp2_dface_t *f : tmp) { + if (f != face) { + resultset.insert(f); + } + } + } + + std::vector result; + for (const bsp2_dface_t *f : resultset) { + result.push_back(f); + } + return result; +} + position_t CalcPointNormal(const mbsp_t *bsp, const bsp2_dface_t *face, const qvec3f &origPoint, bool phongShaded, float face_lmscale, int recursiondepth, const qvec3f &modelOffset) { @@ -2015,6 +2052,39 @@ LightFace_OccludedDebug(lightsurf_t *lightsurf, lightmapdict_t *lightmaps) Lightmap_Save(lightmaps, lightsurf, lightmap, 0); } +static void +LightFace_DebugNeighbours(lightsurf_t *lightsurf, lightmapdict_t *lightmaps) +{ + Q_assert(debugmode == debugmode_debugneighbours); + + /* use a style 0 light map */ + lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, 0, lightsurf); + + const int fnum = Face_GetNum(lightsurf->bsp, lightsurf->face); + + std::vector neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, dump_facenum)); + bool found = false; + for (auto &f : neighbours) { + if (f == lightsurf->face) + found = true; + } + + /* Overwrite each point, red=occluded, green=ok */ + for (int i = 0; i < lightsurf->numpoints; i++) { + lightsample_t *sample = &lightmap->samples[i]; + if (fnum == dump_facenum) {//lightsurf->occluded[i]) { + glm_to_vec3_t(qvec3f(255,0,0), sample->color); + } else if (found) { + glm_to_vec3_t(qvec3f(0,255,0), sample->color); + } else { + glm_to_vec3_t(qvec3f(10,10,10), sample->color); + } + // N.B.: Mark it as un-occluded now, to disable special handling later in the -extra/-extra4 downscaling code + lightsurf->occluded[i] = false; + } + + Lightmap_Save(lightmaps, lightsurf, lightmap, 0); +} /* Dirtmapping borrowed from q3map2, originally by RaP7oR */ @@ -2914,6 +2984,9 @@ LightFace(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globa if (debugmode == debugmode_debugoccluded) LightFace_OccludedDebug(lightsurf, lightmaps); + if (debugmode == debugmode_debugneighbours) + LightFace_DebugNeighbours(lightsurf, lightmaps); + /* Apply gamma, rangescale, and clamp */ LightFace_ScaleAndClamp(lightsurf, lightmaps);