mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
soft: save full rgb light in model
This commit is contained in:
parent
7c31fd9de2
commit
512e128c5a
3 changed files with 29 additions and 32 deletions
|
@ -95,8 +95,7 @@ typedef struct msurface_s
|
|||
|
||||
// lighting info
|
||||
byte styles[MAXLIGHTMAPS];
|
||||
byte *samples; // [numstyles*surfsize]
|
||||
byte *colorsamples; // [numstyles*surfsize*3]
|
||||
byte *samples; // [numstyles*surfsize*3]
|
||||
|
||||
struct msurface_s *nextalphasurface;
|
||||
} msurface_t;
|
||||
|
@ -209,7 +208,6 @@ typedef struct model_s
|
|||
dvis_t *vis;
|
||||
|
||||
byte *lightdata;
|
||||
byte *colordata;
|
||||
|
||||
// for alias models and sprites
|
||||
image_t *skins[MAX_MD2SKINS];
|
||||
|
|
|
@ -122,7 +122,6 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end)
|
|||
int s, t, ds, dt;
|
||||
int i;
|
||||
mtexinfo_t *tex;
|
||||
byte *lightmap;
|
||||
int maps;
|
||||
int r;
|
||||
|
||||
|
@ -158,6 +157,8 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end)
|
|||
surf = r_worldmodel->surfaces + node->firstsurface;
|
||||
for (i=0 ; i<node->numsurfaces ; i++, surf++)
|
||||
{
|
||||
byte *lightmap;
|
||||
|
||||
if (surf->flags&(SURF_DRAWTURB|SURF_DRAWSKY))
|
||||
continue; // no lightmaps
|
||||
|
||||
|
@ -181,7 +182,7 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end)
|
|||
ds >>= 4;
|
||||
dt >>= 4;
|
||||
|
||||
lightmap = surf->colorsamples;
|
||||
lightmap = surf->samples;
|
||||
VectorCopy (vec3_origin, pointcolor);
|
||||
|
||||
lightmap += 3 * (dt * ((surf->extents[0] >> 4) + 1) + ds);
|
||||
|
@ -398,6 +399,7 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
smax = (surf->extents[0]>>4)+1;
|
||||
tmax = (surf->extents[1]>>4)+1;
|
||||
size = smax*tmax;
|
||||
|
||||
if (blocklight_max <= blocklights + size)
|
||||
{
|
||||
r_outoflights = true;
|
||||
|
@ -406,7 +408,6 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
|
||||
if (r_fullbright->value || !r_worldmodel->lightdata)
|
||||
{
|
||||
memset(blocklights, 0, size * sizeof(light_t));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -423,11 +424,26 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
maps++)
|
||||
{
|
||||
unsigned scale;
|
||||
light_t *curr_light, *max_light;
|
||||
|
||||
curr_light = blocklights;
|
||||
max_light = blocklights + size;
|
||||
|
||||
scale = drawsurf->lightadj[maps]; // 8.8 fraction
|
||||
for (i=0 ; i<size ; i++)
|
||||
blocklights[i] += lightmap[i] * scale;
|
||||
lightmap += size; // skip to next lightmap
|
||||
|
||||
do
|
||||
{
|
||||
byte light = sqrt((
|
||||
lightmap[0] * lightmap[0] +
|
||||
lightmap[1] * lightmap[1] +
|
||||
lightmap[2] * lightmap[2]
|
||||
) / 3);
|
||||
*curr_light += light * scale;
|
||||
curr_light++;
|
||||
|
||||
lightmap += 3; /* skip to next lightmap */
|
||||
}
|
||||
while(curr_light < max_light);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,8 +257,7 @@ by taking the brightest component
|
|||
static void
|
||||
Mod_LoadLighting (model_t *loadmodel, byte *mod_base, lump_t *l)
|
||||
{
|
||||
int i, size;
|
||||
pixel_t *in;
|
||||
int size;
|
||||
|
||||
if (!l->filelen)
|
||||
{
|
||||
|
@ -266,22 +265,9 @@ Mod_LoadLighting (model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
return;
|
||||
}
|
||||
|
||||
size = l->filelen/3;
|
||||
size = l->filelen;
|
||||
loadmodel->lightdata = Hunk_Alloc(size);
|
||||
loadmodel->colordata = Hunk_Alloc(size * 3);
|
||||
in = mod_base + l->fileofs;
|
||||
for (i=0 ; i<size ; i++, in+=3)
|
||||
{
|
||||
if (in[0] > in[1] && in[0] > in[2])
|
||||
loadmodel->lightdata[i] = in[0];
|
||||
else if (in[1] > in[0] && in[1] > in[2])
|
||||
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];
|
||||
}
|
||||
memcpy(loadmodel->lightdata, mod_base + l->fileofs, size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -671,12 +657,10 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l)
|
|||
if (i == -1)
|
||||
{
|
||||
out->samples = NULL;
|
||||
out->colorsamples = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
out->samples = loadmodel->lightdata + i/3;
|
||||
out->colorsamples = loadmodel->colordata + i;
|
||||
out->samples = loadmodel->lightdata + i;
|
||||
}
|
||||
|
||||
// set the drawing flags flag
|
||||
|
@ -1022,11 +1006,10 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
|
|||
// lighting is a special case, because we keep only 1 byte out of 3
|
||||
// (=> no colored lighting in soft renderer by default)
|
||||
{
|
||||
int size = header->lumps[LUMP_LIGHTING].filelen/3;
|
||||
int size = header->lumps[LUMP_LIGHTING].filelen;
|
||||
size = (size + 31) & ~31;
|
||||
hunkSize += size;
|
||||
/* save color data */
|
||||
hunkSize += size * 3;
|
||||
hunkSize += size;
|
||||
}
|
||||
|
||||
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), 6);
|
||||
|
|
Loading…
Reference in a new issue