ref_gl4: 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-10-02 14:41:13 +03:00 committed by Denis Pauk
parent 583164f7a5
commit ee757f4100
4 changed files with 17 additions and 15 deletions

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 @@ GL4_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
ri.Sys_Error(ERR_DROP, "GL4_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);

View file

@ -182,15 +182,15 @@ GL4_LM_BuildPolygonFromSurface(gl4model_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 @@ GL4_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 (!GL4_LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t))
{

View file

@ -373,6 +373,7 @@ Mod_LoadFaces(gl4model_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 */