From 7c31fd9de28e4f3122a9158a167d64617f67e43c Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 2 Feb 2022 22:16:17 +0200 Subject: [PATCH] soft: sync model light calculation --- src/client/refresh/soft/header/model.h | 2 ++ src/client/refresh/soft/sw_light.c | 28 +++++++++++++++++--------- src/client/refresh/soft/sw_model.c | 12 +++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/client/refresh/soft/header/model.h b/src/client/refresh/soft/header/model.h index a812386d..7135c97f 100644 --- a/src/client/refresh/soft/header/model.h +++ b/src/client/refresh/soft/header/model.h @@ -96,6 +96,7 @@ typedef struct msurface_s // lighting info byte styles[MAXLIGHTMAPS]; byte *samples; // [numstyles*surfsize] + byte *colorsamples; // [numstyles*surfsize*3] struct msurface_s *nextalphasurface; } msurface_t; @@ -208,6 +209,7 @@ typedef struct model_s dvis_t *vis; byte *lightdata; + byte *colordata; // for alias models and sprites image_t *skins[MAX_MD2SKINS]; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index 05e7f5ee..39bcff41 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -123,9 +123,7 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end) int i; mtexinfo_t *tex; byte *lightmap; - float *scales; int maps; - float samp; int r; if (node->contents != -1) @@ -183,18 +181,30 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end) ds >>= 4; dt >>= 4; - lightmap = surf->samples; + lightmap = surf->colorsamples; VectorCopy (vec3_origin, pointcolor); - lightmap += dt * ((surf->extents[0]>>4)+1) + ds; + + lightmap += 3 * (dt * ((surf->extents[0] >> 4) + 1) + ds); for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; maps++) { - samp = *lightmap * r_modulate->value * (1.0/255); // adjust for gl scale - scales = r_newrefdef.lightstyles[surf->styles[maps]].rgb; - VectorMA (pointcolor, samp, scales, pointcolor); - lightmap += ((surf->extents[0]>>4)+1) * - ((surf->extents[1]>>4)+1); + const float *rgb; + int j; + + rgb = r_newrefdef.lightstyles[surf->styles[maps]].rgb; + + /* Apply light level to models */ + for (j = 0; j < 3; j++) + { + float scale; + + scale = rgb[j] * r_modulate->value; + pointcolor[j] += lightmap[j] * scale * (1.0 / 255); + } + + lightmap += 3 * ((surf->extents[0] >> 4) + 1) * + ((surf->extents[1] >> 4) + 1); } return 1; diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index c5fc8be9..aac6bcc6 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -268,6 +268,7 @@ Mod_LoadLighting (model_t *loadmodel, byte *mod_base, lump_t *l) size = l->filelen/3; loadmodel->lightdata = Hunk_Alloc(size); + loadmodel->colordata = Hunk_Alloc(size * 3); in = mod_base + l->fileofs; for (i=0 ; ilightdata[i] = in[1]; else loadmodel->lightdata[i] = in[2]; + loadmodel->colordata[i*3 + 0] = loadmodel->lightdata[i]; + loadmodel->colordata[i*3 + 1] = loadmodel->lightdata[i]; + loadmodel->colordata[i*3 + 2] = loadmodel->lightdata[i]; } } @@ -665,9 +669,15 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l) out->styles[i] = in->styles[i]; i = LittleLong(in->lightofs); if (i == -1) + { out->samples = NULL; + out->colorsamples = NULL; + } else + { out->samples = loadmodel->lightdata + i/3; + out->colorsamples = loadmodel->colordata + i; + } // set the drawing flags flag @@ -1015,6 +1025,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) int size = header->lumps[LUMP_LIGHTING].filelen/3; size = (size + 31) & ~31; hunkSize += size; + /* save color data */ + hunkSize += size * 3; } hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), 6);