gl3: 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-24 16:53:30 +03:00 committed by Denis Pauk
parent 42465a6b03
commit d3f0fde1ae
7 changed files with 21 additions and 20 deletions

View File

@ -28,7 +28,6 @@
#define REF_MODEL_H
#define VERTEXSIZE 7
#define DEFAULT_LMSHIFT 4
/* in memory representation */
@ -53,7 +52,6 @@ typedef struct msurface_s
short texturemins[2];
short extents[2];
short lmshift;
int light_s, light_t; /* gl lightmap coordinates */

View File

@ -193,13 +193,13 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
return 0;
}
ds >>= 4;
dt >>= 4;
ds >>= surf->lmshift;
dt >>= surf->lmshift;
lightmap = surf->samples;
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 < MAX_LIGHTMAPS_PER_SURFACE && surf->styles[maps] != 255;
maps++)
@ -218,8 +218,8 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
pointcolor[j] += lightmap[j] * scale * (1.0 / 255);
}
lightmap += 3 * ((surf->extents[0] >> 4) + 1) *
((surf->extents[1] >> 4) + 1);
lightmap += 3 * ((surf->extents[0] >> surf->lmshift) + 1) *
((surf->extents[1] >> surf->lmshift) + 1);
}
return 1;
@ -300,8 +300,8 @@ GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
ri.Sys_Error(ERR_DROP, "GL3_BuildLightMap called for non-lit surface");
}
smax = (surf->extents[0] >> 4) + 1;
tmax = (surf->extents[1] >> 4) + 1;
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax;
stride -= (smax << 2);
@ -333,8 +333,8 @@ GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
for (i = 0; i < tmax; i++, dest += stride)
{
memset(dest, c, 4*smax);
dest += 4*smax;
memset(dest, c, 4 * smax);
dest += 4 * smax;
}
}

View File

@ -182,15 +182,15 @@ GL3_LM_BuildPolygonFromSurface(gl3model_t *currentmodel, msurface_t *fa)
/* lightmap texture coordinates */
s = DotProduct(vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
s -= fa->texturemins[0];
s += fa->light_s * 16;
s += 8;
s /= BLOCK_WIDTH * 16; /* fa->texinfo->texture->width; */
s += fa->light_s * (1 << fa->lmshift);
s += (1 << fa->lmshift) * 0.5;
s /= BLOCK_WIDTH * (1 << fa->lmshift);
t = DotProduct(vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
t -= fa->texturemins[1];
t += fa->light_t * 16;
t += 8;
t /= BLOCK_HEIGHT * 16; /* fa->texinfo->texture->height; */
t += fa->light_t * (1 << fa->lmshift);
t += (1 << fa->lmshift) * 0.5;
t /= BLOCK_HEIGHT * (1 << fa->lmshift);
vert->lmTexCoord[0] = s;
vert->lmTexCoord[1] = t;
@ -210,8 +210,8 @@ GL3_LM_CreateSurfaceLightmap(msurface_t *surf)
return;
}
smax = (surf->extents[0] >> 4) + 1;
tmax = (surf->extents[1] >> 4) + 1;
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
if (!GL3_LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t))
{

View File

@ -373,6 +373,7 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l)
}
out->texinfo = loadmodel->texinfo + ti;
out->lmshift = DEFAULT_LMSHIFT;
Mod_CalcSurfaceExtents(loadmodel, out);

View File

@ -67,6 +67,7 @@ typedef struct msurface_s
short texturemins[2];
short extents[2];
short lmshift;
int light_s, light_t; /* gl lightmap coordinates */
int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */

View File

@ -75,6 +75,8 @@ typedef enum
#define MAX_LBM_HEIGHT 480
#define DEFAULT_NOLERP_LIST "pics/conchars.* pics/ch1.* pics/ch2. pics/ch3.*"
#define DEFAULT_LMSHIFT 4
extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
/* Shared images load */

View File

@ -49,7 +49,6 @@ BRUSH MODELS
//
#define VERTEXSIZE 7
#define DEFAULT_LMSHIFT 4
typedef struct vkpoly_s
{