[scene] Support ambient lighting in worldspawn

Abyss of Pandemonium uses global ambient light a lot, but doesn't
specify it in every map (nothing extracting entities and adding a
reasonable value can't fix). I imagine some further tweaking will be
needed.
This commit is contained in:
Bill Currie 2022-05-05 19:53:20 +09:00
parent c26c3b2739
commit df5b471342
3 changed files with 20 additions and 4 deletions

View file

@ -38,7 +38,6 @@
struct mod_brush_s;
#define NumStyles 64
#define NoStyle -1
#define LM_LINEAR 0 // light - dist (or radius + dist if -ve)
#define LM_INVERSE 1 // distFactor1 * light / dist

View file

@ -232,8 +232,16 @@ locate_lights (model_t *model, lightingdata_t *ldata)
light_t *lights = ldata->lights.a;
DARRAY_RESIZE (&ldata->lightleafs, ldata->lights.size);
for (size_t i = 0; i < ldata->lights.size; i++) {
mleaf_t *leaf = Mod_PointInLeaf (&lights[i].position[0], model);
ldata->lightleafs.a[i] = leaf - model->brush.leafs - 1;
if (1 || lights[i].position[3]) {
mleaf_t *leaf = Mod_PointInLeaf (&lights[i].position[0], model);
ldata->lightleafs.a[i] = leaf - model->brush.leafs - 1;
} else {
if (DotProduct (lights[i].direction, lights[i].direction)) {
ldata->lightleafs.a[i] = -1;
} else {
ldata->lightleafs.a[i] = -2;
}
}
}
}
@ -271,6 +279,15 @@ CL_LoadLights (plitem_t *entities, scene_t *scene)
if (!strcmp (classname, "worldspawn")) {
// parse_sun can add many lights
parse_sun (ldata, entity);
const char *str;
if ((str = PL_String (PL_ObjectForKey (entity, "light_lev")))) {
light_t light = {};
light.color = (vec4f_t) { 1, 1, 1, atof (str) };
light.attenuation = (vec4f_t) { 0, 0, 1, 0 };
light.direction = (vec4f_t) { 0, 0, 0, 1 };
DARRAY_APPEND (&ldata->lights, light);
DARRAY_APPEND (&ldata->lightstyles, 0);
}
} else if (!strncmp (classname, "light", 5)) {
light_t light = {};
int style = 0;

View file

@ -128,7 +128,7 @@ Light_FindVisibleLights (lightingdata_t *ldata)
memset (ldata->lightvis.a, 0, ldata->lightvis.size * sizeof (byte));
for (size_t i = 0; i < ldata->lightleafs.size; i++) {
int l = ldata->lightleafs.a[i];
if ((l == -1 && (flags & SURF_DRAWSKY))
if ((l == -2) || (l == -1 && (flags & SURF_DRAWSKY))
|| set_is_member (ldata->pvs, l)) {
ldata->lightvis.a[i] = 1;
visible++;