From bbf4a9f1898772dce2053b26cb3094a7f063e510 Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Thu, 24 Aug 2023 16:53:30 +0300 Subject: [PATCH] soft: LIGHTMAPS: Add support for LMSHIFT. Could be extended to support the LMSHIFT BSPX blob. Currently mostly a cleanup to make DECOUPLEDLM changes more readable. --- src/client/refresh/soft/header/model.h | 1 + src/client/refresh/soft/sw_light.c | 29 +++++++++++++------------- src/client/refresh/soft/sw_model.c | 1 + src/client/refresh/soft/sw_surf.c | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/client/refresh/soft/header/model.h b/src/client/refresh/soft/header/model.h index 8156b417..8dd7ffc0 100644 --- a/src/client/refresh/soft/header/model.h +++ b/src/client/refresh/soft/header/model.h @@ -59,6 +59,7 @@ typedef struct msurface_s short texturemins[2]; short extents[2]; + short lmshift; mtexinfo_t *texinfo; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index caf1a715..4db6b254 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -141,13 +141,13 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor) if (!surf->samples) 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 < MAXLIGHTMAPS && surf->styles[maps] != 255 ; maps++) @@ -166,8 +166,8 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor) 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; @@ -252,8 +252,8 @@ R_AddDynamicLights (drawsurf_t* drawsurf) mtexinfo_t *tex; surf = drawsurf->surf; - 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; tex = surf->texinfo; if (blocklight_max <= blocklights + smax*tmax*3) @@ -318,24 +318,23 @@ R_AddDynamicLights (drawsurf_t* drawsurf) local[0] -= surf->texturemins[0]; local[1] -= surf->texturemins[1]; - for (t = 0 ; tlmshift); if (td < 0) td = -td; for (s=0 ; slmshift); if (sd < 0) sd = -sd; if (sd > td) - dist = sd + (td>>1); + dist = sd + (td >> 1); else - dist = td + (sd>>1); + dist = td + (sd >> 1); for (i=0; i<3; i++) { @@ -378,8 +377,8 @@ R_BuildLightMap (drawsurf_t* drawsurf) surf = drawsurf->surf; - 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*3; if (blocklight_max <= blocklights + size) diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 7414be95..44498dc0 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -447,6 +447,7 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l) ri.Sys_Error(ERR_DROP, "%s: bad texinfo number", __func__); } out->texinfo = loadmodel->texinfo + ti; + out->lmshift = DEFAULT_LMSHIFT; CalcSurfaceExtents (loadmodel, out); diff --git a/src/client/refresh/soft/sw_surf.c b/src/client/refresh/soft/sw_surf.c index 32c7c10e..ffe1a87f 100644 --- a/src/client/refresh/soft/sw_surf.c +++ b/src/client/refresh/soft/sw_surf.c @@ -197,7 +197,7 @@ R_DrawSurface (drawsurf_t *drawsurf) blocksize = 16 >> drawsurf->surfmip; blockdivshift = NUM_MIPS - drawsurf->surfmip; - r_lightwidth = (drawsurf->surf->extents[0]>>4)+1; + r_lightwidth = (drawsurf->surf->extents[0] >> drawsurf->surf->lmshift) + 1; r_numhblocks = drawsurf->surfwidth >> blockdivshift; r_numvblocks = drawsurf->surfheight >> blockdivshift;