light: convert modelinfo_t to use settings system
This commit is contained in:
parent
a5f8af389f
commit
5566e1f85d
|
|
@ -62,18 +62,6 @@ typedef struct {
|
|||
vec3_t direction;
|
||||
} lightsample_t;
|
||||
|
||||
typedef struct {
|
||||
const dmodel_t *model;
|
||||
qboolean shadowself; /* is it shadow casting only on itself? */
|
||||
qboolean shadow; /* is it shadow casting? */
|
||||
lightsample_t minlight;
|
||||
char minlight_exclude[16]; /* texture name to exclude from minlight */
|
||||
float lightmapscale;
|
||||
vec3_t offset;
|
||||
qboolean nodirt;
|
||||
vec_t phongangle;
|
||||
} modelinfo_t;
|
||||
|
||||
typedef struct sun_s {
|
||||
vec3_t sunvec;
|
||||
lightsample_t sunlight;
|
||||
|
|
@ -100,7 +88,9 @@ typedef struct {
|
|||
const texinfo_t *texinfo;
|
||||
vec_t planedist;
|
||||
} texorg_t;
|
||||
|
||||
|
||||
class modelinfo_t;
|
||||
|
||||
/*Warning: this stuff needs explicit initialisation*/
|
||||
typedef struct {
|
||||
const modelinfo_t *modelinfo;
|
||||
|
|
@ -604,24 +594,28 @@ public:
|
|||
{}
|
||||
};
|
||||
|
||||
class modelsettings_t {
|
||||
class modelinfo_t {
|
||||
public:
|
||||
const dmodel_t *model;
|
||||
float lightmapscale;
|
||||
vec3_t offset;
|
||||
|
||||
public:
|
||||
lockable_vec_t minlight, shadow, shadowself, dirt, phong, phong_angle;
|
||||
lockable_string_t minlight_exclude;
|
||||
lockable_vec3_t minlight_color;
|
||||
private:
|
||||
settingsdict_t settings;
|
||||
|
||||
public:
|
||||
modelsettings_t(void) :
|
||||
modelinfo_t(void) :
|
||||
minlight { "minlight", 0 },
|
||||
shadow { "shadow", 0 },
|
||||
shadowself { "shadowself", 0 },
|
||||
dirt { "dirt", 0 },
|
||||
phong { "phong", 0 },
|
||||
phong_angle { "phong_angle", 0 },
|
||||
phong_angle { "phong_angle", 89 },
|
||||
minlight_exclude { "minlight_exclude", "" },
|
||||
minlight_color { "minlight_color", 255, 255, 255 },
|
||||
minlight_color { "minlight_color", 255, 255, 255, vec3_transformer_t::NORMALIZE_COLOR_TO_255 },
|
||||
settings {{
|
||||
&minlight, &shadow, &shadowself, &dirt, &phong, &phong_angle,
|
||||
&minlight_exclude, &minlight_color
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ byte *lux_filebase; // start of luxfile data
|
|||
static byte *lux_file_p; // start of free space after luxfile data
|
||||
static byte *lux_file_end; // end of space for luxfile data
|
||||
|
||||
static modelinfo_t *modelinfo;
|
||||
std::vector<modelinfo_t> modelinfo;
|
||||
const modelinfo_t *const *tracelist;
|
||||
const modelinfo_t *const *selfshadowlist;
|
||||
|
||||
|
|
@ -334,7 +334,6 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
const char *attribute;
|
||||
const modelinfo_t **shadowmodels;
|
||||
const modelinfo_t **selfshadowmodels;
|
||||
modelinfo_t *info;
|
||||
float lightmapscale;
|
||||
|
||||
shadowmodels = (const modelinfo_t **)malloc(sizeof(modelinfo_t *) * (bsp->nummodels + 1));
|
||||
|
|
@ -352,9 +351,6 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
Error("Corrupt .BSP: bsp->nummodels is 0!");
|
||||
}
|
||||
|
||||
memset(modelinfo, 0, sizeof(*modelinfo) * bsp->nummodels);
|
||||
modelinfo[0].model = &bsp->dmodels[0];
|
||||
|
||||
if (lmscaleoverride)
|
||||
SetWorldKeyValue("_lightmap_scale", lmscaleoverride);
|
||||
|
||||
|
|
@ -370,12 +366,19 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
i++;
|
||||
if (i != lightmapscale)
|
||||
logprint("WARNING: lightmap scale is not a power of 2\n");
|
||||
modelinfo[0].lightmapscale = lightmapscale;
|
||||
modelinfo[0].shadow = true; /* world always casts shadows */
|
||||
|
||||
for (i = 1, info = modelinfo + 1; i < bsp->nummodels; i++, info++) {
|
||||
info->model = &bsp->dmodels[i];
|
||||
info->lightmapscale = lightmapscale;
|
||||
|
||||
modelinfo.reserve(bsp->nummodels);
|
||||
|
||||
modelinfo_t world;
|
||||
world.model = &bsp->dmodels[0];
|
||||
world.lightmapscale = lightmapscale;
|
||||
world.shadow.setFloatValue(1.0f); /* world always casts shadows */
|
||||
modelinfo.push_back(world);
|
||||
|
||||
for (int i = 1; i < bsp->nummodels; i++) {
|
||||
modelinfo_t info;
|
||||
info.model = &bsp->dmodels[i];
|
||||
info.lightmapscale = lightmapscale;
|
||||
|
||||
/* Find the entity for the model */
|
||||
snprintf(modelname, sizeof(modelname), "*%d", i);
|
||||
|
|
@ -387,54 +390,48 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
/* Check if this model will cast shadows (shadow => shadowself) */
|
||||
shadow = atoi(ValueForKey(entity, "_shadow"));
|
||||
if (shadow) {
|
||||
shadowmodels[numshadowmodels++] = info;
|
||||
info->shadow = true;
|
||||
shadowmodels[numshadowmodels++] = &modelinfo[i];
|
||||
info.shadow.setFloatValue(1.0f);
|
||||
} else {
|
||||
shadow = atoi(ValueForKey(entity, "_shadowself"));
|
||||
if (shadow) {
|
||||
info->shadowself = true;
|
||||
selfshadowmodels[numselfshadowmodels++] = info;
|
||||
info.shadowself.setFloatValue(1.0f);
|
||||
selfshadowmodels[numselfshadowmodels++] = &modelinfo[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up the offset for rotate_* entities */
|
||||
attribute = ValueForKey(entity, "classname");
|
||||
if (!strncmp(attribute, "rotate_", 7))
|
||||
GetVectorForKey(entity, "origin", info->offset);
|
||||
GetVectorForKey(entity, "origin", info.offset);
|
||||
|
||||
/* Grab the bmodel minlight values, if any */
|
||||
attribute = ValueForKey(entity, "_minlight");
|
||||
if (attribute[0])
|
||||
info->minlight.light = atoi(attribute);
|
||||
info.minlight.setFloatValue(atoi(attribute));
|
||||
const char *minlight_exclude = ValueForKey(entity, "_minlight_exclude");
|
||||
if (minlight_exclude[0] != '\0') {
|
||||
strncpy(info->minlight_exclude, minlight_exclude, 15);
|
||||
info->minlight_exclude[15] = '\0';
|
||||
info.minlight_exclude.setStringValue(minlight_exclude);
|
||||
}
|
||||
GetVectorForKey(entity, "_mincolor", info->minlight.color);
|
||||
normalize_color_format(info->minlight.color);
|
||||
if (!VectorCompare(info->minlight.color, vec3_origin)) {
|
||||
if (!write_litfile)
|
||||
|
||||
vec3_t tmp;
|
||||
GetVectorForKey(entity, "_mincolor", tmp);
|
||||
if (!VectorCompare(tmp, vec3_origin)) {
|
||||
info.minlight_color.setVec3Value(tmp);
|
||||
}
|
||||
|
||||
vec3_t white = {255,255,255};
|
||||
if (!VectorCompare(white, *info.minlight_color.vec3Value())) {
|
||||
if (!write_litfile) {
|
||||
write_litfile = scaledonly?2:1;
|
||||
} else {
|
||||
VectorCopy(vec3_white, info->minlight.color);
|
||||
}
|
||||
|
||||
/* Check for disabled dirtmapping on this bmodel */
|
||||
if (atoi(ValueForKey(entity, "_dirt")) == -1) {
|
||||
info->nodirt = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for phong shading */
|
||||
// handle "_phong" and "_phong_angle"
|
||||
info->phongangle = atof(ValueForKey(entity, "_phong_angle"));
|
||||
const int phong = atoi(ValueForKey(entity, "_phong"));
|
||||
|
||||
if (phong && (info->phongangle == 0.0)) {
|
||||
info->phongangle = 89.0; // default _phong_angle
|
||||
}
|
||||
modelinfo.push_back(info);
|
||||
}
|
||||
|
||||
assert(modelinfo.size() == bsp->nummodels);
|
||||
|
||||
tracelist = shadowmodels;
|
||||
selfshadowlist = selfshadowmodels;
|
||||
}
|
||||
|
|
@ -599,7 +596,7 @@ CalcualateVertexNormals(const bsp2_t *bsp)
|
|||
// support on func_detail/func_group
|
||||
for (int i=0; i<bsp->nummodels; i++) {
|
||||
const modelinfo_t *info = &modelinfo[i];
|
||||
const uint8_t phongangle_byte = (uint8_t) qmax(0, qmin(255, (int)rint(info->phongangle)));
|
||||
const uint8_t phongangle_byte = (uint8_t) qmax(0, qmin(255, (int)rint(info->phong_angle.floatValue())));
|
||||
|
||||
if (!phongangle_byte)
|
||||
continue;
|
||||
|
|
@ -1730,7 +1727,6 @@ main(int argc, const char **argv)
|
|||
FindDebugFace(bsp);
|
||||
FindDebugVert(bsp);
|
||||
|
||||
modelinfo = (modelinfo_t *)malloc(bsp->nummodels * sizeof(*modelinfo));
|
||||
FindModelInfo(bsp, lmscaleoverride);
|
||||
SetupLights(bsp);
|
||||
|
||||
|
|
@ -1782,8 +1778,6 @@ main(int argc, const char **argv)
|
|||
logprint("%5.3f seconds elapsed\n", end - start);
|
||||
|
||||
close_log();
|
||||
|
||||
free(modelinfo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -593,7 +593,7 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co
|
|||
|
||||
plane_t hitplane = {0};
|
||||
|
||||
const dmodel_t *selfshadow = (surf->modelinfo->shadowself) ? surf->modelinfo->model : NULL;
|
||||
const dmodel_t *selfshadow = (surf->modelinfo->shadowself.boolValue()) ? surf->modelinfo->model : NULL;
|
||||
|
||||
vec3_t dirn;
|
||||
VectorSubtract(testpoint, surf->midpoint, dirn);
|
||||
|
|
@ -862,9 +862,10 @@ Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face,
|
|||
else
|
||||
lightsurf->lightmapscale = modelinfo->lightmapscale;
|
||||
|
||||
// FIXME: is modelinfo used?!?
|
||||
lightsurf->curved = !!(extended_texinfo_flags[face->texinfo] & TEX_PHONG_ANGLE_MASK);
|
||||
lightsurf->nodirt = !!(extended_texinfo_flags[face->texinfo] & TEX_NODIRT);
|
||||
lightsurf->minlight = modelinfo->minlight;
|
||||
VectorCopy(*modelinfo->minlight_color.vec3Value(), lightsurf->minlight.color);
|
||||
lightsurf->minlight.light = (extended_texinfo_flags[face->texinfo] & TEX_MINLIGHT_MASK) >> TEX_MINLIGHT_SHIFT;
|
||||
/* fixup minlight color */
|
||||
if (lightsurf->minlight.light > 0 && VectorCompare(lightsurf->minlight.color, vec3_origin)) {
|
||||
|
|
@ -1356,7 +1357,7 @@ LightFace_Entity(const bsp2_t *bsp,
|
|||
*/
|
||||
hit = false;
|
||||
lightmap = Lightmap_ForStyle(lightmaps, entity->style, lightsurf);
|
||||
shadowself = modelinfo->shadowself ? modelinfo->model : NULL;
|
||||
shadowself = modelinfo->shadowself.boolValue() ? modelinfo->model : NULL;
|
||||
sample = lightmap->samples;
|
||||
surfpoint = lightsurf->points[0];
|
||||
surfnorm = lightsurf->normals[0];
|
||||
|
|
@ -1459,7 +1460,7 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmap_t *lightm
|
|||
|
||||
/* Check each point... */
|
||||
hit = false;
|
||||
shadowself = modelinfo->shadowself ? modelinfo->model : NULL;
|
||||
shadowself = modelinfo->shadowself.boolValue() ? modelinfo->model : NULL;
|
||||
sample = lightmap->samples;
|
||||
surfpoint = lightsurf->points[0];
|
||||
surfnorm = lightsurf->normals[0];
|
||||
|
|
@ -1512,7 +1513,7 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face,
|
|||
lightmap_t *lightmap;
|
||||
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
if (texname[0] != '\0' && !strcmp(texname, modelinfo->minlight_exclude))
|
||||
if (texname[0] != '\0' && modelinfo->minlight_exclude.stringValue() == std::string{ texname })
|
||||
return; /* this texture is excluded from minlight */
|
||||
|
||||
/* Find a style 0 lightmap */
|
||||
|
|
@ -1536,7 +1537,7 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face,
|
|||
Lightmap_Save(lightmaps, lightsurf, lightmap, 0);
|
||||
|
||||
/* Cast rays for local minlight entities */
|
||||
shadowself = modelinfo->shadowself ? modelinfo->model : NULL;
|
||||
shadowself = modelinfo->shadowself.boolValue() ? modelinfo->model : NULL;
|
||||
for (entity = lights; *entity; entity++) {
|
||||
if ((*entity)->formula != LF_LOCALMIN)
|
||||
continue;
|
||||
|
|
@ -1904,7 +1905,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
|
|||
static void
|
||||
LightFace_CalculateDirt(lightsurf_t *lightsurf)
|
||||
{
|
||||
const dmodel_t *selfshadow = lightsurf->modelinfo->shadowself ? lightsurf->modelinfo->model : NULL;
|
||||
const dmodel_t *selfshadow = lightsurf->modelinfo->shadowself.boolValue() ? lightsurf->modelinfo->model : NULL;
|
||||
for (int i = 0; i < lightsurf->numpoints; i++) {
|
||||
lightsurf->occlusion[i] = DirtForSample(selfshadow, lightsurf->points[i], lightsurf->normals[i]);
|
||||
}
|
||||
|
|
@ -2275,7 +2276,7 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
|
|||
|
||||
if (bounce.boolValue()) {
|
||||
// make bounce light, only if this face is shadow casting
|
||||
if (modelinfo->shadow) {
|
||||
if (modelinfo->shadow.boolValue()) {
|
||||
vec3_t gray = {127, 127, 127};
|
||||
|
||||
// lerp between gray and the texture color according to `bouncecolorscale`
|
||||
|
|
|
|||
Loading…
Reference in New Issue