ref_gl1: LIGHTMAPS: Add support for LMSHIFT.

Could be extended to support the LMSHIFT BSPX blob. Currently mostly a
cleanup to make DECOUPLEDLM changes more readable.
This commit is contained in:
Daniel Svensson 2023-08-23 18:05:35 +03:00 committed by Denis Pauk
parent a11b298d5c
commit 27331bcd1c
7 changed files with 40 additions and 36 deletions

View file

@ -805,7 +805,7 @@ Mod_PointInLeaf(const vec3_t p, mnode_t *node)
} }
const void * const void *
Mod_LoadBSPXFindLump(bspx_header_t *bspx_header, const char *lumpname, Mod_LoadBSPXFindLump(const bspx_header_t *bspx_header, const char *lumpname,
int *plumpsize, const byte *mod_base) int *plumpsize, const byte *mod_base)
{ {
bspx_lump_t *lump; bspx_lump_t *lump;

View file

@ -267,16 +267,15 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
return 0; return 0;
} }
ds >>= 4; ds >>= surf->lmshift;
dt >>= 4; dt >>= surf->lmshift;
lightmap = surf->samples; lightmap = surf->samples;
VectorCopy(vec3_origin, pointcolor); VectorCopy(vec3_origin, pointcolor);
lightmap += 3 * (dt * ((surf->extents[0] >> 4) + 1) + ds); lightmap += 3 * (dt * ((surf->extents[0] >> surf->lmshift) + 1) + ds);
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
maps++)
{ {
const float *rgb; const float *rgb;
int j; int j;
@ -292,8 +291,8 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
pointcolor[j] += lightmap[j] * scale * (1.0 / 255); pointcolor[j] += lightmap[j] * scale * (1.0 / 255);
} }
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * lightmap += 3 * ((surf->extents[0] >> surf->lmshift) + 1) *
((surf->extents[1] >> 4) + 1); ((surf->extents[1] >> surf->lmshift) + 1);
} }
return 1; return 1;
@ -311,7 +310,6 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
int lnum; int lnum;
dlight_t *dl; dlight_t *dl;
vec3_t dist; vec3_t dist;
float add;
if (!r_worldmodel->lightdata || !currententity) if (!r_worldmodel->lightdata || !currententity)
{ {
@ -339,6 +337,8 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++) for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++)
{ {
float add;
VectorSubtract(currententity->origin, VectorSubtract(currententity->origin,
dl->origin, dist); dl->origin, dist);
add = dl->intensity - VectorLength(dist); add = dl->intensity - VectorLength(dist);
@ -368,8 +368,8 @@ R_AddDynamicLights(msurface_t *surf)
float *pfBL; float *pfBL;
float fsacc, ftacc; float fsacc, ftacc;
smax = (surf->extents[0] >> 4) + 1; smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> 4) + 1; tmax = (surf->extents[1] >> surf->lmshift) + 1;
tex = surf->texinfo; tex = surf->texinfo;
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++)
@ -408,7 +408,7 @@ R_AddDynamicLights(msurface_t *surf)
pfBL = s_blocklights; pfBL = s_blocklights;
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16) for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
{ {
td = local[1] - ftacc; td = local[1] - ftacc;
@ -417,7 +417,7 @@ R_AddDynamicLights(msurface_t *surf)
td = -td; td = -td;
} }
for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBL += 3) for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), pfBL += 3)
{ {
sd = Q_ftol(local[0] - fsacc); sd = Q_ftol(local[0] - fsacc);
@ -437,9 +437,11 @@ R_AddDynamicLights(msurface_t *surf)
if (fdist < fminlight) if (fdist < fminlight)
{ {
pfBL[0] += (frad - fdist) * dl->color[0]; float diff = frad - fdist;
pfBL[1] += (frad - fdist) * dl->color[1];
pfBL[2] += (frad - fdist) * dl->color[2]; pfBL[0] += diff * dl->color[0];
pfBL[1] += diff * dl->color[1];
pfBL[2] += diff * dl->color[2];
} }
} }
} }
@ -479,8 +481,8 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
ri.Sys_Error(ERR_DROP, "R_BuildLightMap called for non-lit surface"); ri.Sys_Error(ERR_DROP, "R_BuildLightMap called for non-lit surface");
} }
smax = (surf->extents[0] >> 4) + 1; smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> 4) + 1; tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax; size = smax * tmax;
if (size > (sizeof(s_blocklights) >> 4)) if (size > (sizeof(s_blocklights) >> 4))
@ -665,4 +667,3 @@ store:
} }
} }
} }

View file

@ -189,15 +189,15 @@ LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa)
/* lightmap texture coordinates */ /* lightmap texture coordinates */
s = DotProduct(vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; s = DotProduct(vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
s -= fa->texturemins[0]; s -= fa->texturemins[0];
s += fa->light_s * 16; s += fa->light_s * (1 << fa->lmshift);
s += 8; s += (1 << fa->lmshift) * 0.5;
s /= BLOCK_WIDTH * 16; /* fa->texinfo->texture->width; */ s /= BLOCK_WIDTH * (1 << fa->lmshift);
t = DotProduct(vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; t = DotProduct(vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
t -= fa->texturemins[1]; t -= fa->texturemins[1];
t += fa->light_t * 16; t += fa->light_t * (1 << fa->lmshift);
t += 8; t += (1 << fa->lmshift) * 0.5;
t /= BLOCK_HEIGHT * 16; /* fa->texinfo->texture->height; */ t /= BLOCK_HEIGHT * (1 << fa->lmshift);
poly->verts[i][5] = s; poly->verts[i][5] = s;
poly->verts[i][6] = t; poly->verts[i][6] = t;
@ -215,8 +215,8 @@ LM_CreateSurfaceLightmap(msurface_t *surf)
return; return;
} }
smax = (surf->extents[0] >> 4) + 1; smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> 4) + 1; tmax = (surf->extents[1] >> surf->lmshift) + 1;
if (!LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t)) if (!LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t))
{ {

View file

@ -502,6 +502,7 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l)
} }
out->texinfo = loadmodel->texinfo + ti; out->texinfo = loadmodel->texinfo + ti;
out->lmshift = DEFAULT_LMSHIFT;
Mod_CalcSurfaceExtents(loadmodel, out); Mod_CalcSurfaceExtents(loadmodel, out);
@ -702,14 +703,14 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
Mod_LoadSurfedges(mod->name, &mod->surfedges, &mod->numsurfedges, Mod_LoadSurfedges(mod->name, &mod->surfedges, &mod->numsurfedges,
mod_base, &header->lumps[LUMP_SURFEDGES], 0); mod_base, &header->lumps[LUMP_SURFEDGES], 0);
Mod_LoadLighting(&mod->lightdata, mod_base, &header->lumps[LUMP_LIGHTING]); Mod_LoadLighting(&mod->lightdata, mod_base, &header->lumps[LUMP_LIGHTING]);
Mod_LoadPlanes (mod->name, &mod->planes, &mod->numplanes, Mod_LoadPlanes(mod->name, &mod->planes, &mod->numplanes,
mod_base, &header->lumps[LUMP_PLANES], 0); mod_base, &header->lumps[LUMP_PLANES], 0);
Mod_LoadTexinfo(mod->name, &mod->texinfo, &mod->numtexinfo, Mod_LoadTexinfo(mod->name, &mod->texinfo, &mod->numtexinfo,
mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)R_FindImage, mod_base, &header->lumps[LUMP_TEXINFO], (findimage_t)R_FindImage,
r_notexture, 0); r_notexture, 0);
Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]); Mod_LoadFaces(mod, mod_base, &header->lumps[LUMP_FACES]);
Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]); Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]);
Mod_LoadVisibility (&mod->vis, mod_base, &header->lumps[LUMP_VISIBILITY]); Mod_LoadVisibility(&mod->vis, mod_base, &header->lumps[LUMP_VISIBILITY]);
Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]); Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]);
Mod_LoadNodes(mod->name, mod->planes, mod->numplanes, mod->leafs, Mod_LoadNodes(mod->name, mod->planes, mod->numplanes, mod->leafs,
mod->numleafs, &mod->nodes, &mod->numnodes, mod_base, mod->numleafs, &mod->nodes, &mod->numnodes, mod_base,
@ -829,4 +830,3 @@ RI_EndRegistration(void)
R_FreeUnusedImages(); R_FreeUnusedImages();
} }

View file

@ -325,8 +325,8 @@ R_BlendLightmaps(const model_t *currentmodel)
int smax, tmax; int smax, tmax;
byte *base; byte *base;
smax = (surf->extents[0] >> 4) + 1; smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> 4) + 1; tmax = (surf->extents[1] >> surf->lmshift) + 1;
if (LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t)) if (LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t))
{ {
@ -511,8 +511,8 @@ R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
unsigned temp[34 * 34]; unsigned temp[34 * 34];
int smax, tmax; int smax, tmax;
smax = (fa->extents[0] >> 4) + 1; smax = (fa->extents[0] >> fa->lmshift) + 1;
tmax = (fa->extents[1] >> 4) + 1; tmax = (fa->extents[1] >> fa->lmshift) + 1;
R_BuildLightMap(fa, (void *)temp, smax * 4); R_BuildLightMap(fa, (void *)temp, smax * 4);
R_SetCacheState(fa); R_SetCacheState(fa);

View file

@ -27,7 +27,8 @@
#ifndef REF_MODEL_H #ifndef REF_MODEL_H
#define REF_MODEL_H #define REF_MODEL_H
#define VERTEXSIZE 7 #define VERTEXSIZE 7
#define DEFAULT_LMSHIFT 4
/* in memory representation */ /* in memory representation */
@ -53,6 +54,8 @@ typedef struct msurface_s
short texturemins[2]; short texturemins[2];
short extents[2]; short extents[2];
short lmshift;
int light_s, light_t; /* gl lightmap coordinates */ int light_s, light_t; /* gl lightmap coordinates */
int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */ int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */

View file

@ -209,7 +209,7 @@ extern void Mod_LoadSurfedges (const char *name, int **surfedges, int *numsurfed
const byte *mod_base, const lump_t *l, int extra); const byte *mod_base, const lump_t *l, int extra);
extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra); extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra);
extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node); extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node);
extern const void *Mod_LoadBSPXFindLump(bspx_header_t *bspx_header, extern const void *Mod_LoadBSPXFindLump(const bspx_header_t *bspx_header,
const char *lumpname, int *plumpsize, const byte *mod_base); const char *lumpname, int *plumpsize, const byte *mod_base);
extern const bspx_header_t *Mod_LoadBSPX(int filesize, const byte *mod_base); extern const bspx_header_t *Mod_LoadBSPX(int filesize, const byte *mod_base);