light: add -bouncelightsdebug switch to render bounce lights
This commit is contained in:
parent
801d9652c0
commit
46a56df19f
|
|
@ -161,7 +161,8 @@ typedef enum {
|
|||
debugmode_none = 0,
|
||||
debugmode_phong,
|
||||
debugmode_dirt,
|
||||
debugmode_bounce
|
||||
debugmode_bounce,
|
||||
debugmode_bouncelights
|
||||
} debugmode_t;
|
||||
|
||||
extern debugmode_t debugmode;
|
||||
|
|
@ -398,6 +399,7 @@ const modelinfo_t *ModelInfoForFace(const bsp2_t *bsp, int facenum);
|
|||
const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, const int v);
|
||||
const bsp2_dface_t *Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgeindex);
|
||||
const std::vector<bouncelight_t> &BounceLights();
|
||||
std::vector<bouncelight_t> BounceLightsForFaceNum(int facenum);
|
||||
bool Leaf_HasSky(const bsp2_t *bsp, const bsp2_dleaf_t *leaf);
|
||||
int light_main(int argc, const char **argv);
|
||||
|
||||
|
|
|
|||
|
|
@ -750,6 +750,7 @@ LoadExtendedTexinfoFlags(const char *sourcefilename, const bsp2_t *bsp)
|
|||
mutex radlights_lock;
|
||||
map<string, vec3_struct_t> texturecolors;
|
||||
std::vector<bouncelight_t> radlights;
|
||||
std::map<int, std::vector<bouncelight_t>> radlightsByFacenum; // duplicate of `radlights` but indexed by face
|
||||
|
||||
class patch_t {
|
||||
public:
|
||||
|
|
@ -833,7 +834,7 @@ Face_LookupTextureColor(const bsp2_t *bsp, const bsp2_dface_t *face, vec3_t colo
|
|||
}
|
||||
|
||||
static void
|
||||
AddBounceLight(const vec3_t pos, const vec3_t color, const vec3_t surfnormal, vec_t area, const bsp2_t *bsp);
|
||||
AddBounceLight(const vec3_t pos, const vec3_t color, const vec3_t surfnormal, vec_t area, const bsp2_dface_t *face, const bsp2_t *bsp);
|
||||
|
||||
static void *
|
||||
MakeBounceLightsThread (void *arg)
|
||||
|
|
@ -905,14 +906,14 @@ MakeBounceLightsThread (void *arg)
|
|||
emitcolor[k] = (sum[k] / 255.0f) * (blendedcolor[k] / 255.0f);
|
||||
}
|
||||
|
||||
AddBounceLight(facemidpoint, emitcolor, faceplane.normal, facearea, bsp);
|
||||
AddBounceLight(facemidpoint, emitcolor, faceplane.normal, facearea, face, bsp);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
AddBounceLight(const vec3_t pos, const vec3_t color, const vec3_t surfnormal, vec_t area, const bsp2_t *bsp)
|
||||
AddBounceLight(const vec3_t pos, const vec3_t color, const vec3_t surfnormal, vec_t area, const bsp2_dface_t *face, const bsp2_t *bsp)
|
||||
{
|
||||
Q_assert(color[0] >= 0);
|
||||
Q_assert(color[1] >= 0);
|
||||
|
|
@ -931,6 +932,7 @@ AddBounceLight(const vec3_t pos, const vec3_t color, const vec3_t surfnormal, ve
|
|||
|
||||
unique_lock<mutex> lck { radlights_lock };
|
||||
radlights.push_back(l);
|
||||
radlightsByFacenum[Face_GetNum(bsp, face)].push_back(l);
|
||||
}
|
||||
|
||||
const std::vector<bouncelight_t> &BounceLights()
|
||||
|
|
@ -938,6 +940,15 @@ const std::vector<bouncelight_t> &BounceLights()
|
|||
return radlights;
|
||||
}
|
||||
|
||||
std::vector<bouncelight_t> BounceLightsForFaceNum(int facenum)
|
||||
{
|
||||
const auto &vec = radlightsByFacenum.find(facenum);
|
||||
if (vec != radlightsByFacenum.end()) {
|
||||
return vec->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Returns color in [0,1]
|
||||
static void
|
||||
Texture_AvgColor (const bsp2_t *bsp, const miptex_t *miptex, vec3_t color)
|
||||
|
|
@ -1459,6 +1470,11 @@ light_main(int argc, const char **argv)
|
|||
cfg.bounce.setBoolValueLocked(true);
|
||||
debugmode = debugmode_bounce;
|
||||
logprint( "Bounce debugging mode enabled on command line\n" );
|
||||
} else if ( !strcmp( argv[ i ], "-bouncelightsdebug" ) ) {
|
||||
CheckNoDebugModeSet();
|
||||
cfg.bounce.setBoolValueLocked(true);
|
||||
debugmode = debugmode_bouncelights;
|
||||
logprint( "Bounce emitters debugging mode enabled on command line\n" );
|
||||
} else if ( !strcmp( argv[ i ], "-surflight_subdivide" ) ) {
|
||||
surflight_subdivide = ParseVec(&i, argc, argv);
|
||||
surflight_subdivide = qmin(qmax(surflight_subdivide, 64.0f), 2048.0f);
|
||||
|
|
|
|||
|
|
@ -1620,6 +1620,32 @@ LightFace_PhongDebug(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps)
|
|||
Lightmap_Save(lightmaps, lightsurf, lightmap, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
LightFace_BounceLightsDebug(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps)
|
||||
{
|
||||
Q_assert(debugmode == debugmode_bouncelights);
|
||||
|
||||
/* use a style 0 light map */
|
||||
lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, 0, lightsurf);
|
||||
|
||||
vec3_t patch_color = {0,0,0};
|
||||
std::vector<bouncelight_t> vpls = BounceLightsForFaceNum(Face_GetNum(lightsurf->bsp, lightsurf->face));
|
||||
if (vpls.size()) {
|
||||
Q_assert(vpls.size() == 1); // for now only 1 vpl per face
|
||||
|
||||
const auto &vpl = vpls.at(0);
|
||||
VectorScale(vpl.color, 255, patch_color);
|
||||
}
|
||||
|
||||
/* Overwrite each point with the emitted color... */
|
||||
for (int i = 0; i < lightsurf->numpoints; i++) {
|
||||
lightsample_t *sample = &lightmap->samples[i];
|
||||
VectorCopy(patch_color, sample->color);
|
||||
}
|
||||
|
||||
Lightmap_Save(lightmaps, lightsurf, lightmap, 0);
|
||||
}
|
||||
|
||||
// returns color in [0,255]
|
||||
static inline void
|
||||
BounceLight_ColorAtDist(const globalconfig_t &cfg, const bouncelight_t *vpl, vec_t dist, vec3_t color)
|
||||
|
|
@ -2358,6 +2384,9 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
if (debugmode == debugmode_phong)
|
||||
LightFace_PhongDebug(lightsurf, lightmaps);
|
||||
|
||||
if (debugmode == debugmode_bouncelights)
|
||||
LightFace_BounceLightsDebug(lightsurf, lightmaps);
|
||||
|
||||
/* Fix any negative values */
|
||||
for (lightmap_t &lightmap : *lightmaps) {
|
||||
for (int j = 0; j < lightsurf->numpoints; j++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue