From ac2a50cb4ac264a7209f1ab388b152e671e924fb Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 6 Jul 2024 16:48:14 +0300 Subject: [PATCH] soft: scale model texture s,t values ref_gl renders use 0.0..1.0 float texture coordinates in gl commands and skin ratio/resolution could be any. ref_soft render uses absolute coordinates as result textures with different to expected size are applied incorrectly. Fix will not add support of scalled retextured skins, just fix case when ratio is incorrect after scale down such or place a incorrect pcx skin to the model directory. --- src/client/refresh/soft/header/local.h | 2 ++ src/client/refresh/soft/sw_alias.c | 6 +++-- src/client/refresh/soft/sw_polyset.c | 37 ++++++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index da4f6c27..0df50bc3 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -221,6 +221,8 @@ typedef struct pixel_t *pskin; int skinwidth; int skinheight; + float scalewidth; + float scaleheight; } affinetridesc_t; typedef struct diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 1726cf86..2426c303 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -526,8 +526,10 @@ R_AliasSetupSkin(const entity_t *currententity, const model_t *currentmodel) return false; r_affinetridesc.pskin = pskindesc->pixels[0]; - r_affinetridesc.skinwidth = pskindesc->width; - r_affinetridesc.skinheight = pskindesc->height; + r_affinetridesc.skinwidth = pskindesc->asset_width; + r_affinetridesc.skinheight = pskindesc->asset_height; + r_affinetridesc.scalewidth = (float)pskindesc->asset_width / s_pmdl->skinwidth; + r_affinetridesc.scaleheight = (float)pskindesc->asset_height / s_pmdl->skinheight; return true; } diff --git a/src/client/refresh/soft/sw_polyset.c b/src/client/refresh/soft/sw_polyset.c index acfd6a10..a3c8bbe0 100644 --- a/src/client/refresh/soft/sw_polyset.c +++ b/src/client/refresh/soft/sw_polyset.c @@ -273,27 +273,41 @@ FloorDivMod(int numer, int denom, int *quo, int *rem) #if defined(__i386__) || defined(__amd64__) q = numer / denom; r = numer - q * denom; + if (-1/2 || 1/-2 || -1/-2) { // long live C89 if (r < 0 && r < denom) { q += 1; r -= denom; } - } else { + } + else + { // C99 always truncates to 0 - if ((numer ^ denom) < 0 && r != 0) { + if ((numer ^ denom) < 0 && r != 0) + { q -= 1; r += denom; } } + if ((numer < 0) ^ (denom < 0)) + { assert(q <= 0); + } else + { assert(q >= 0); + } + if (denom < 0) + { assert(r > denom && r <= 0); + } else + { assert(r >= 0 && r < denom); + } #else float num = numer, den = denom; float x; @@ -754,8 +768,8 @@ R_PolysetDrawSpans8_Opaque (const entity_t *currententity, spanpackage_t *pspanp } static void -R_ProcessLeftEdge(compactvert_t *plefttop, compactvert_t *prighttop, - compactvert_t *pleftbottom) +R_ProcessLeftEdge(const compactvert_t *plefttop, const compactvert_t *prighttop, + const compactvert_t *pleftbottom) { light3_t working_lstepx; pixel_t *d_ptex; @@ -768,8 +782,8 @@ R_ProcessLeftEdge(compactvert_t *plefttop, compactvert_t *prighttop, v = plefttop->v; d_aspancount = plefttop->u - prighttop->u; - s = plefttop->s; - t = plefttop->t; + s = plefttop->s * r_affinetridesc.scalewidth; + t = plefttop->t * r_affinetridesc.scaleheight; i = (s >> SHIFT16XYZ) + (t >> SHIFT16XYZ) * r_affinetridesc.skinwidth; d_ptex = &r_affinetridesc.pskin[i]; d_sfrac = s & 0xFFFF; @@ -794,7 +808,9 @@ R_ProcessLeftEdge(compactvert_t *plefttop, compactvert_t *prighttop, // ceil (), but plus a little bit) t = ubasestep < 0; for (i = 0; i < 3; i++) + { working_lstepx[i] = r_lstepx[i] - t; + } // base steps for drawers s = r_sstepy + r_sstepx * ubasestep; @@ -805,7 +821,9 @@ R_ProcessLeftEdge(compactvert_t *plefttop, compactvert_t *prighttop, d_tfracbasestep = t & 0xFFFF; for (i = 0; i < 3; i++) + { d_lightbasestep[i] = r_lstepy[i] + working_lstepx[i] * ubasestep; + } d_zibasestep = r_zistepy + r_zistepx * ubasestep; @@ -818,7 +836,9 @@ R_ProcessLeftEdge(compactvert_t *plefttop, compactvert_t *prighttop, d_tfracextrastep = t & 0xFFFF; for (i = 0; i < 3; i++) + { d_lightextrastep[i] = d_lightbasestep[i] + working_lstepx[i]; + } d_ziextrastep = d_zibasestep + r_zistepx; @@ -833,7 +853,8 @@ R_RasterizeAliasPolySmooth static void R_RasterizeAliasPolySmooth(const entity_t *currententity) { - compactvert_t *plefttop, *prighttop, *pleftbottom, *prightbottom; + const compactvert_t *pleftbottom, *prightbottom; + const compactvert_t *plefttop, *prighttop; spanpackage_t *pstart; int originalcount; int leftheight, rightheight; @@ -924,7 +945,7 @@ R_PolysetSetEdgeTable ================ */ static void -R_PolysetSetEdgeTable (void) +R_PolysetSetEdgeTable(void) { int edgetableindex;