From cd013405e7ee027939468a1540cc4c4eaf7726f8 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 13 Jul 2016 21:51:04 -0600 Subject: [PATCH] light: convert more settings to lockable_*_t --- include/light/light.hh | 49 +++++++++++++++++++++++++----------------- light/entities.cc | 38 ++++++++++++++++---------------- light/light.cc | 34 +++++++++++++++-------------- light/ltface.cc | 24 +++++++++++++-------- 4 files changed, 81 insertions(+), 64 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index cf7b6330..07a0da26 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -213,25 +213,7 @@ const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, co const bsp2_dface_t * Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgeindex); - -extern float scaledist; -extern float rangescale; -extern float global_anglescale; -extern float fadegate; -extern int softsamples; -extern float lightmapgamma; -extern const vec3_t vec3_white; -extern float surflight_subdivide; -extern int sunsamples; -extern qboolean addminlight; -extern lightsample_t minlight; - -extern sun_t *suns; - -extern int dump_facenum; -extern bool dump_face; - /* command-line options */ class lockable_vec_t { @@ -241,6 +223,14 @@ public: vec_t value; bool locked; + bool boolValue() const { + return static_cast(value); + } + + float floatValue() const { + return value; + } + lockable_vec_t(std::vector names, vec_t v, bool l = false) : _names(names), value(v), locked(l) {} @@ -251,13 +241,13 @@ public: class lockable_vec3_t { private: std::vector _names; - + public: vec3_t value; bool locked; lockable_vec3_t(std::vector names, vec_t a, vec_t b, vec_t c, bool l = false) - : _names(names), locked(l) + : _names(names), locked(l) { VectorSet(value, a, b, c); } @@ -266,6 +256,25 @@ public: : lockable_vec3_t(std::vector { name }, a,b,c,l) {} }; +extern lockable_vec_t scaledist; +extern lockable_vec_t rangescale; +extern lockable_vec_t global_anglescale; +extern float fadegate; +extern int softsamples; +extern lockable_vec_t lightmapgamma; +extern const vec3_t vec3_white; +extern float surflight_subdivide; +extern int sunsamples; + +extern lockable_vec_t addminlight; +extern lockable_vec_t minlight; +extern lockable_vec3_t minlight_color; + +extern sun_t *suns; + +extern int dump_facenum; +extern bool dump_face; + /* dirt */ extern lockable_vec_t dirty; // should any dirtmapping take place? diff --git a/light/entities.cc b/light/entities.cc index 8dfbc5e6..8ef0a351 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -212,7 +212,7 @@ CheckEntityFields(entity_t *entity) if (entity->atten <= 0.0) entity->atten = 1.0; if (entity->anglescale < 0 || entity->anglescale > 1.0) - entity->anglescale = global_anglescale; + entity->anglescale = global_anglescale.floatValue(); if (entity->formula < LF_LINEAR || entity->formula >= LF_COUNT) { static qboolean warned_once = true; @@ -240,7 +240,7 @@ CheckEntityFields(entity_t *entity) if (entity->formula == LF_INVERSE || entity->formula == LF_INVERSE2 || entity->formula == LF_INFINITE - || (entity->formula == LF_LOCALMIN && addminlight) + || (entity->formula == LF_LOCALMIN && addminlight.boolValue()) || entity->formula == LF_INVERSE2A) { entity->light.light /= entity->num_samples; } @@ -292,7 +292,7 @@ AddSun(vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt) VectorScale(sun->sunvec, -16384, sun->sunvec); sun->sunlight.light = light; VectorCopy(color, sun->sunlight.color); - sun->anglescale = global_anglescale; + sun->anglescale = global_anglescale.floatValue(); sun->dirt = Dirt_ResolveFlag(dirtInt); // add to list @@ -1068,8 +1068,8 @@ LoadEntities(const bsp2_t *bsp) normalize_color_format(sunlight3_color.value); } } else if (!strcmp(key, "_minlight_color")) { - scan_vec3(minlight.color, com_token, "_minlight_color"); - normalize_color_format(minlight.color); + scan_vec3(minlight_color.value, com_token, "_minlight_color"); + normalize_color_format(minlight_color.value); } else if (!strcmp(key, "_anglesense") || !strcmp(key, "_anglescale")) entity->anglescale = atof(com_token); else if (!strcmp(key, "_dirtdepth")) @@ -1135,8 +1135,8 @@ LoadEntities(const bsp2_t *bsp) entity->range = atof(com_token); } else if (!strcmp(key, "_gamma")) { - lightmapgamma = atof(com_token); - logprint("using lightmap gamma value %f\n", lightmapgamma); + lightmapgamma.value = atof(com_token); + logprint("using lightmap gamma value %f\n", lightmapgamma.floatValue()); } else if (!strcmp(key, "_bounce")) { if (!bounce.locked) { @@ -1182,30 +1182,30 @@ LoadEntities(const bsp2_t *bsp) } } if (!strcmp(entity->classname(), "worldspawn")) { - if (entity->light.light > 0 && !minlight.light) { - minlight.light = entity->light.light; + if (entity->light.light > 0 && !minlight.value) { + minlight.value = entity->light.light; logprint("using minlight value %i from worldspawn.\n", - (int)minlight.light); - } else if (minlight.light) { + (int)minlight.value); + } else if (minlight.value) { logprint("Using minlight value %i from command line.\n", - (int)minlight.light); + (int)minlight.value); } if (entity->anglescale >= 0 && entity->anglescale <= 1.0) { - global_anglescale = entity->anglescale; + global_anglescale.value = entity->anglescale; logprint("using global anglescale value %f from worldspawn.\n", - global_anglescale); + global_anglescale.floatValue()); } if (entity->dist != 0.0) { - scaledist = entity->dist; + scaledist.value = entity->dist; logprint("using _dist value %f from worldspawn.\n", - scaledist); + scaledist.floatValue()); } if (entity->range != 0.0) { - rangescale = entity->range; + rangescale.value = entity->range; logprint("using _range value %f from worldspawn.\n", - rangescale); + rangescale.floatValue()); } if (entity->dirtdepth && !dirtDepth.locked) { @@ -1275,7 +1275,7 @@ LoadEntities(const bsp2_t *bsp) } if (!VectorCompare(sunlight_color.value, vec3_white) || - !VectorCompare(minlight.color, vec3_white) || + !VectorCompare(minlight_color.value, vec3_white) || !VectorCompare(sunlight2_color.value, vec3_white) || !VectorCompare(sunlight3_color.value, vec3_white)) { if (!write_litfile) { diff --git a/light/light.cc b/light/light.cc index 8036675f..296d3545 100644 --- a/light/light.cc +++ b/light/light.cc @@ -41,22 +41,24 @@ using namespace std; -float scaledist = 1.0; -float rangescale = 0.5; -float global_anglescale = 0.5; +using strings = std::vector; + +lockable_vec_t scaledist {"dist", 1.0}; +lockable_vec_t rangescale {"range", 0.5}; +lockable_vec_t global_anglescale {strings{"anglescale", "anglesense"}, 0.5}; float fadegate = EQUAL_EPSILON; int softsamples = 0; -float lightmapgamma = 1.0; +lockable_vec_t lightmapgamma {"gamma", 1.0}; const vec3_t vec3_white = { 255, 255, 255 }; float surflight_subdivide = 128.0f; int sunsamples = 64; qboolean scaledonly = false; -qboolean addminlight = false; -lightsample_t minlight = { 0, { 255, 255, 255 } }; -sun_t *suns = NULL; +lockable_vec_t addminlight {"addmin", 0}; +lockable_vec_t minlight {"light", 0}; +lockable_vec3_t minlight_color {strings{"minlight_color", "min_color"}, 255.0f, 255.0f, 255.0f}; -using strings = std::vector; +sun_t *suns = NULL; /* dirt */ lockable_vec_t dirty {strings{"dirt", "dirty"}, 0.0f}; @@ -1442,21 +1444,21 @@ main(int argc, const char **argv) oversample = 4; logprint("extra 4x4 sampling enabled\n"); } else if (!strcmp(argv[i], "-dist")) { - scaledist = ParseVec(&i, argc, argv); + scaledist.value = ParseVec(&i, argc, argv); } else if (!strcmp(argv[i], "-range")) { - rangescale = ParseVec(&i, argc, argv); + rangescale.value = ParseVec(&i, argc, argv); } else if (!strcmp(argv[i], "-gate")) { fadegate = ParseVec(&i, argc, argv); if (fadegate > 1) { logprint( "WARNING: -gate value greater than 1 may cause artifacts\n" ); } } else if (!strcmp(argv[i], "-light")) { - minlight.light = ParseVec(&i, argc, argv); + minlight.value = ParseVec(&i, argc, argv); } else if (!strcmp(argv[i], "-addmin")) { - addminlight = true; + addminlight.value = true; } else if (!strcmp(argv[i], "-gamma")) { - lightmapgamma = ParseVec(&i, argc, argv); - logprint( "Lightmap gamma %f specified on command-line.\n", lightmapgamma ); + lightmapgamma.value = ParseVec(&i, argc, argv); + logprint( "Lightmap gamma %f specified on command-line.\n", lightmapgamma.floatValue() ); } else if (!strcmp(argv[i], "-lit")) { write_litfile |= 1; } else if (!strcmp(argv[i], "-lit2")) { @@ -1484,8 +1486,8 @@ main(int argc, const char **argv) else softsamples = -1; /* auto, based on oversampling */ } else if (!strcmp(argv[i], "-anglescale") || !strcmp(argv[i], "-anglesense")) { - global_anglescale = ParseVec(&i, argc, argv); - logprint("Using global anglescale value of %f from command line.\n", global_anglescale); + global_anglescale.value = ParseVec(&i, argc, argv); + logprint("Using global anglescale value of %f from command line.\n", global_anglescale.floatValue()); } else if ( !strcmp( argv[ i ], "-dirt" ) ) { int dirt_param = 1; ParseIntOptional(&dirt_param, &i, argc, argv); diff --git a/light/ltface.cc b/light/ltface.cc index 3c51d812..ec092f5f 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1071,7 +1071,7 @@ GetLightValue(const lightsample_t *light, const entity_t *entity, vec_t dist) if (entity->formula == LF_INFINITE || entity->formula == LF_LOCALMIN) return light->light; - value = scaledist * entity->atten * dist; + value = scaledist.floatValue() * entity->atten * dist; switch (entity->formula) { case LF_INVERSE: return light->light / (value / LF_SCALE); @@ -1530,7 +1530,7 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face, vec_t value = light->light; if (minlightDirt) value *= Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf); - if (addminlight) + if (addminlight.boolValue()) Light_Add(sample, value, light->color, vec3_origin); else Light_ClampMin(sample, value, light->color); @@ -1553,13 +1553,13 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face, sample = lightmap->samples; surfpoint = lightsurf->points[0]; for (j = 0; j < lightsurf->numpoints; j++, sample++, surfpoint += 3) { - if (addminlight || sample->light < (*entity)->light.light) { + if (addminlight.boolValue() || sample->light < (*entity)->light.light) { vec_t value = (*entity)->light.light; trace = TestLight((*entity)->origin, surfpoint, shadowself); if (!trace) continue; value *= Dirt_GetScaleFactor(lightsurf->occlusion[j], (*entity), lightsurf); - if (addminlight) + if (addminlight.boolValue()) Light_Add(sample, value, (*entity)->light.color, vec3_origin); else Light_ClampMin(sample, value, (*entity)->light.color); @@ -1998,9 +1998,9 @@ WriteLightmaps(const bsp2_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const /* Scale and clamp any out-of-range samples */ maxcolor = 0; - VectorScale(color, rangescale, color); + VectorScale(color, rangescale.floatValue(), color); for (i = 0; i < 3; i++) - color[i] = pow( color[i] / 255.0f, 1.0 / lightmapgamma ) * 255.0f; + color[i] = pow( color[i] / 255.0f, 1.0 / lightmapgamma.floatValue() ) * 255.0f; for (i = 0; i < 3; i++) if (color[i] > maxcolor) maxcolor = color[i]; @@ -2196,10 +2196,16 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, LightFace_Sky (sun, lightsurf, lightmaps); /* minlight - Use the greater of global or model minlight. */ - if (lightsurf->minlight.light > minlight.light) + if (lightsurf->minlight.light > minlight.value) LightFace_Min(bsp, face, &lightsurf->minlight, lightsurf, lightmaps); - else - LightFace_Min(bsp, face, &minlight, lightsurf, lightmaps); + else { + lightsample_t ls; + ls.light = minlight.value; + VectorCopy(minlight_color.value, ls.color); + VectorSet(ls.direction, 0, 0, 0); + + LightFace_Min(bsp, face, &ls, lightsurf, lightmaps); + } /* negative lights */ for (lighte = lights; (entity = *lighte); lighte++)