mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-21 03:11:57 +00:00
soft: sync model light calculation
This commit is contained in:
parent
5535773521
commit
7c31fd9de2
3 changed files with 33 additions and 9 deletions
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ; i<size ; i++, in+=3)
|
||||
{
|
||||
|
@ -277,6 +278,9 @@ Mod_LoadLighting (model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
loadmodel->lightdata[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);
|
||||
|
|
Loading…
Reference in a new issue