light: convert more settings to lockable_*_t

This commit is contained in:
Eric Wasylishen 2016-07-13 21:51:04 -06:00
parent 42657f9607
commit cd013405e7
4 changed files with 81 additions and 64 deletions

View File

@ -213,25 +213,7 @@ const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, co
const bsp2_dface_t * const bsp2_dface_t *
Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgeindex); 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 */ /* command-line options */
class lockable_vec_t { class lockable_vec_t {
@ -241,6 +223,14 @@ public:
vec_t value; vec_t value;
bool locked; bool locked;
bool boolValue() const {
return static_cast<bool>(value);
}
float floatValue() const {
return value;
}
lockable_vec_t(std::vector<std::string> names, vec_t v, bool l = false) lockable_vec_t(std::vector<std::string> names, vec_t v, bool l = false)
: _names(names), value(v), locked(l) {} : _names(names), value(v), locked(l) {}
@ -251,13 +241,13 @@ public:
class lockable_vec3_t { class lockable_vec3_t {
private: private:
std::vector<std::string> _names; std::vector<std::string> _names;
public: public:
vec3_t value; vec3_t value;
bool locked; bool locked;
lockable_vec3_t(std::vector<std::string> names, vec_t a, vec_t b, vec_t c, bool l = false) lockable_vec3_t(std::vector<std::string> 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); VectorSet(value, a, b, c);
} }
@ -266,6 +256,25 @@ public:
: lockable_vec3_t(std::vector<std::string> { name }, a,b,c,l) {} : lockable_vec3_t(std::vector<std::string> { 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 */ /* dirt */
extern lockable_vec_t dirty; // should any dirtmapping take place? extern lockable_vec_t dirty; // should any dirtmapping take place?

View File

@ -212,7 +212,7 @@ CheckEntityFields(entity_t *entity)
if (entity->atten <= 0.0) if (entity->atten <= 0.0)
entity->atten = 1.0; entity->atten = 1.0;
if (entity->anglescale < 0 || entity->anglescale > 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) { if (entity->formula < LF_LINEAR || entity->formula >= LF_COUNT) {
static qboolean warned_once = true; static qboolean warned_once = true;
@ -240,7 +240,7 @@ CheckEntityFields(entity_t *entity)
if (entity->formula == LF_INVERSE if (entity->formula == LF_INVERSE
|| entity->formula == LF_INVERSE2 || entity->formula == LF_INVERSE2
|| entity->formula == LF_INFINITE || entity->formula == LF_INFINITE
|| (entity->formula == LF_LOCALMIN && addminlight) || (entity->formula == LF_LOCALMIN && addminlight.boolValue())
|| entity->formula == LF_INVERSE2A) { || entity->formula == LF_INVERSE2A) {
entity->light.light /= entity->num_samples; 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); VectorScale(sun->sunvec, -16384, sun->sunvec);
sun->sunlight.light = light; sun->sunlight.light = light;
VectorCopy(color, sun->sunlight.color); VectorCopy(color, sun->sunlight.color);
sun->anglescale = global_anglescale; sun->anglescale = global_anglescale.floatValue();
sun->dirt = Dirt_ResolveFlag(dirtInt); sun->dirt = Dirt_ResolveFlag(dirtInt);
// add to list // add to list
@ -1068,8 +1068,8 @@ LoadEntities(const bsp2_t *bsp)
normalize_color_format(sunlight3_color.value); normalize_color_format(sunlight3_color.value);
} }
} else if (!strcmp(key, "_minlight_color")) { } else if (!strcmp(key, "_minlight_color")) {
scan_vec3(minlight.color, com_token, "_minlight_color"); scan_vec3(minlight_color.value, com_token, "_minlight_color");
normalize_color_format(minlight.color); normalize_color_format(minlight_color.value);
} else if (!strcmp(key, "_anglesense") || !strcmp(key, "_anglescale")) } else if (!strcmp(key, "_anglesense") || !strcmp(key, "_anglescale"))
entity->anglescale = atof(com_token); entity->anglescale = atof(com_token);
else if (!strcmp(key, "_dirtdepth")) else if (!strcmp(key, "_dirtdepth"))
@ -1135,8 +1135,8 @@ LoadEntities(const bsp2_t *bsp)
entity->range = atof(com_token); entity->range = atof(com_token);
} }
else if (!strcmp(key, "_gamma")) { else if (!strcmp(key, "_gamma")) {
lightmapgamma = atof(com_token); lightmapgamma.value = atof(com_token);
logprint("using lightmap gamma value %f\n", lightmapgamma); logprint("using lightmap gamma value %f\n", lightmapgamma.floatValue());
} }
else if (!strcmp(key, "_bounce")) { else if (!strcmp(key, "_bounce")) {
if (!bounce.locked) { if (!bounce.locked) {
@ -1182,30 +1182,30 @@ LoadEntities(const bsp2_t *bsp)
} }
} }
if (!strcmp(entity->classname(), "worldspawn")) { if (!strcmp(entity->classname(), "worldspawn")) {
if (entity->light.light > 0 && !minlight.light) { if (entity->light.light > 0 && !minlight.value) {
minlight.light = entity->light.light; minlight.value = entity->light.light;
logprint("using minlight value %i from worldspawn.\n", logprint("using minlight value %i from worldspawn.\n",
(int)minlight.light); (int)minlight.value);
} else if (minlight.light) { } else if (minlight.value) {
logprint("Using minlight value %i from command line.\n", logprint("Using minlight value %i from command line.\n",
(int)minlight.light); (int)minlight.value);
} }
if (entity->anglescale >= 0 && entity->anglescale <= 1.0) { 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", logprint("using global anglescale value %f from worldspawn.\n",
global_anglescale); global_anglescale.floatValue());
} }
if (entity->dist != 0.0) { if (entity->dist != 0.0) {
scaledist = entity->dist; scaledist.value = entity->dist;
logprint("using _dist value %f from worldspawn.\n", logprint("using _dist value %f from worldspawn.\n",
scaledist); scaledist.floatValue());
} }
if (entity->range != 0.0) { if (entity->range != 0.0) {
rangescale = entity->range; rangescale.value = entity->range;
logprint("using _range value %f from worldspawn.\n", logprint("using _range value %f from worldspawn.\n",
rangescale); rangescale.floatValue());
} }
if (entity->dirtdepth && !dirtDepth.locked) { if (entity->dirtdepth && !dirtDepth.locked) {
@ -1275,7 +1275,7 @@ LoadEntities(const bsp2_t *bsp)
} }
if (!VectorCompare(sunlight_color.value, vec3_white) || 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(sunlight2_color.value, vec3_white) ||
!VectorCompare(sunlight3_color.value, vec3_white)) { !VectorCompare(sunlight3_color.value, vec3_white)) {
if (!write_litfile) { if (!write_litfile) {

View File

@ -41,22 +41,24 @@
using namespace std; using namespace std;
float scaledist = 1.0; using strings = std::vector<std::string>;
float rangescale = 0.5;
float global_anglescale = 0.5; 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; float fadegate = EQUAL_EPSILON;
int softsamples = 0; int softsamples = 0;
float lightmapgamma = 1.0; lockable_vec_t lightmapgamma {"gamma", 1.0};
const vec3_t vec3_white = { 255, 255, 255 }; const vec3_t vec3_white = { 255, 255, 255 };
float surflight_subdivide = 128.0f; float surflight_subdivide = 128.0f;
int sunsamples = 64; int sunsamples = 64;
qboolean scaledonly = false; qboolean scaledonly = false;
qboolean addminlight = false; lockable_vec_t addminlight {"addmin", 0};
lightsample_t minlight = { 0, { 255, 255, 255 } }; lockable_vec_t minlight {"light", 0};
sun_t *suns = NULL; lockable_vec3_t minlight_color {strings{"minlight_color", "min_color"}, 255.0f, 255.0f, 255.0f};
using strings = std::vector<std::string>; sun_t *suns = NULL;
/* dirt */ /* dirt */
lockable_vec_t dirty {strings{"dirt", "dirty"}, 0.0f}; lockable_vec_t dirty {strings{"dirt", "dirty"}, 0.0f};
@ -1442,21 +1444,21 @@ main(int argc, const char **argv)
oversample = 4; oversample = 4;
logprint("extra 4x4 sampling enabled\n"); logprint("extra 4x4 sampling enabled\n");
} else if (!strcmp(argv[i], "-dist")) { } else if (!strcmp(argv[i], "-dist")) {
scaledist = ParseVec(&i, argc, argv); scaledist.value = ParseVec(&i, argc, argv);
} else if (!strcmp(argv[i], "-range")) { } else if (!strcmp(argv[i], "-range")) {
rangescale = ParseVec(&i, argc, argv); rangescale.value = ParseVec(&i, argc, argv);
} else if (!strcmp(argv[i], "-gate")) { } else if (!strcmp(argv[i], "-gate")) {
fadegate = ParseVec(&i, argc, argv); fadegate = ParseVec(&i, argc, argv);
if (fadegate > 1) { if (fadegate > 1) {
logprint( "WARNING: -gate value greater than 1 may cause artifacts\n" ); logprint( "WARNING: -gate value greater than 1 may cause artifacts\n" );
} }
} else if (!strcmp(argv[i], "-light")) { } else if (!strcmp(argv[i], "-light")) {
minlight.light = ParseVec(&i, argc, argv); minlight.value = ParseVec(&i, argc, argv);
} else if (!strcmp(argv[i], "-addmin")) { } else if (!strcmp(argv[i], "-addmin")) {
addminlight = true; addminlight.value = true;
} else if (!strcmp(argv[i], "-gamma")) { } else if (!strcmp(argv[i], "-gamma")) {
lightmapgamma = ParseVec(&i, argc, argv); lightmapgamma.value = ParseVec(&i, argc, argv);
logprint( "Lightmap gamma %f specified on command-line.\n", lightmapgamma ); logprint( "Lightmap gamma %f specified on command-line.\n", lightmapgamma.floatValue() );
} else if (!strcmp(argv[i], "-lit")) { } else if (!strcmp(argv[i], "-lit")) {
write_litfile |= 1; write_litfile |= 1;
} else if (!strcmp(argv[i], "-lit2")) { } else if (!strcmp(argv[i], "-lit2")) {
@ -1484,8 +1486,8 @@ main(int argc, const char **argv)
else else
softsamples = -1; /* auto, based on oversampling */ softsamples = -1; /* auto, based on oversampling */
} else if (!strcmp(argv[i], "-anglescale") || !strcmp(argv[i], "-anglesense")) { } else if (!strcmp(argv[i], "-anglescale") || !strcmp(argv[i], "-anglesense")) {
global_anglescale = ParseVec(&i, argc, argv); global_anglescale.value = ParseVec(&i, argc, argv);
logprint("Using global anglescale value of %f from command line.\n", global_anglescale); logprint("Using global anglescale value of %f from command line.\n", global_anglescale.floatValue());
} else if ( !strcmp( argv[ i ], "-dirt" ) ) { } else if ( !strcmp( argv[ i ], "-dirt" ) ) {
int dirt_param = 1; int dirt_param = 1;
ParseIntOptional(&dirt_param, &i, argc, argv); ParseIntOptional(&dirt_param, &i, argc, argv);

View File

@ -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) if (entity->formula == LF_INFINITE || entity->formula == LF_LOCALMIN)
return light->light; return light->light;
value = scaledist * entity->atten * dist; value = scaledist.floatValue() * entity->atten * dist;
switch (entity->formula) { switch (entity->formula) {
case LF_INVERSE: case LF_INVERSE:
return light->light / (value / LF_SCALE); 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; vec_t value = light->light;
if (minlightDirt) if (minlightDirt)
value *= Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf); value *= Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf);
if (addminlight) if (addminlight.boolValue())
Light_Add(sample, value, light->color, vec3_origin); Light_Add(sample, value, light->color, vec3_origin);
else else
Light_ClampMin(sample, value, light->color); Light_ClampMin(sample, value, light->color);
@ -1553,13 +1553,13 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face,
sample = lightmap->samples; sample = lightmap->samples;
surfpoint = lightsurf->points[0]; surfpoint = lightsurf->points[0];
for (j = 0; j < lightsurf->numpoints; j++, sample++, surfpoint += 3) { 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; vec_t value = (*entity)->light.light;
trace = TestLight((*entity)->origin, surfpoint, shadowself); trace = TestLight((*entity)->origin, surfpoint, shadowself);
if (!trace) if (!trace)
continue; continue;
value *= Dirt_GetScaleFactor(lightsurf->occlusion[j], (*entity), lightsurf); value *= Dirt_GetScaleFactor(lightsurf->occlusion[j], (*entity), lightsurf);
if (addminlight) if (addminlight.boolValue())
Light_Add(sample, value, (*entity)->light.color, vec3_origin); Light_Add(sample, value, (*entity)->light.color, vec3_origin);
else else
Light_ClampMin(sample, value, (*entity)->light.color); 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 */ /* Scale and clamp any out-of-range samples */
maxcolor = 0; maxcolor = 0;
VectorScale(color, rangescale, color); VectorScale(color, rangescale.floatValue(), color);
for (i = 0; i < 3; i++) 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++) for (i = 0; i < 3; i++)
if (color[i] > maxcolor) if (color[i] > maxcolor)
maxcolor = color[i]; maxcolor = color[i];
@ -2196,10 +2196,16 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
LightFace_Sky (sun, lightsurf, lightmaps); LightFace_Sky (sun, lightsurf, lightmaps);
/* minlight - Use the greater of global or model minlight. */ /* 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); LightFace_Min(bsp, face, &lightsurf->minlight, lightsurf, lightmaps);
else else {
LightFace_Min(bsp, face, &minlight, lightsurf, lightmaps); 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 */ /* negative lights */
for (lighte = lights; (entity = *lighte); lighte++) for (lighte = lights; (entity = *lighte); lighte++)