This code includes a hack to force liquid surfaces' lightmaps to always be saved, otherwise fully dark liquids would remain fullbright.
Code: Select all
static int backwater; // mankrip
static void
LightFace_Entity(const entity_t *entity, const lightsample_t *light,
const lightsurf_t *lightsurf, lightmap_t *lightmaps)
{
const modelinfo_t *modelinfo = lightsurf->modelinfo;
const plane_t *plane = &lightsurf->plane;
const dmodel_t *shadowself;
const vec_t *surfpoint;
int i;
qboolean hit;
vec_t dist, add, angle, spotscale;
lightsample_t *sample;
lightmap_t *lightmap;
vec3_t anormal; // mankrip
dist = DotProduct(entity->origin, plane->normal) - plane->dist;
VectorCopy (plane->normal, anormal); // mankrip
/* don't bother with lights behind the surface */
if (dist < 0)
// mankrip - begin
{
if (!backwater)
// mankrip - end
return;
// mankrip - begin
VectorInverse (anormal);
}
// mankrip - end
/* don't bother with light too far away */
if (dist > entity->fadedist)
if (!backwater) // mankrip
return;
/*
* Check it for real
*/
hit = false;
hit = backwater; // mankrip
lightmap = Lightmap_ForStyle(lightmaps, entity->style);
shadowself = modelinfo->shadowself ? modelinfo->model : NULL;
sample = lightmap->samples;
surfpoint = lightsurf->points[0];
for (i = 0; i < lightsurf->numpoints; i++, sample++, surfpoint += 3) {
vec3_t ray;
VectorSubtract(entity->origin, surfpoint, ray);
dist = VectorLength(ray);
/* Quick distance check first */
if (dist > entity->fadedist)
continue;
/* Check spotlight cone */
VectorScale(ray, 1.0 / dist, ray);
angle = DotProduct(ray, anormal); // mankrip - edited
[...]
}
void
LightFace(bsp2_dface_t *face, const modelinfo_t *modelinfo,
const bsp2_t *bsp)
{
int i, j, k;
const entity_t *entity;
lightsample_t *sample;
lightsurf_t lightsurf;
sun_t *sun;
/* One extra lightmap is allocated to simplify handling overflow */
lightmap_t lightmaps[MAXLIGHTMAPS + 1];
/* some surfaces don't need lightmaps */
face->lightofs = -1;
for (i = 0; i < MAXLIGHTMAPS; i++)
face->styles[i] = 255;
if (bsp->texinfo[face->texinfo].flags & TEX_SPECIAL)
return;
// mankrip - begin
{
const texinfo_t *tex = &bsp->texinfo[face->texinfo];
const int offset = bsp->dtexdata.header->dataofs[tex->miptex];
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
backwater = (miptex->name[0] == '*');
}
// mankrip - end
[...]
}