soft: use lightmap convert table

This commit is contained in:
Denis Pauk 2022-03-20 14:34:40 +02:00
parent 6af5dc1d98
commit b5d45d0371
3 changed files with 42 additions and 10 deletions

View file

@ -97,6 +97,7 @@ extern viddef_t vid;
extern pixel_t *vid_buffer; // invisible buffer
extern pixel_t *vid_colormap; // 256 * VID_GRADES size
extern pixel_t *vid_alphamap; // 256 * 256 translucency map
extern byte *vid_lightmap; // 64 light grades for 256 colors
extern char shift_size; // shift size in fixed-point
typedef struct

View file

@ -337,19 +337,18 @@ static byte *d_16to8table = NULL; // 16 to 8 bit conversion table
pixel_t
R_ApplyLight(pixel_t pix, const light3_t light)
{
pixel_t i_r, i_g, i_b;
byte b_r, b_g, b_b;
int i_c;
/* get index of color component of each component */
i_r = vid_colormap[(light[0] & 0xFF00) + pix];
i_g = vid_colormap[(light[1] & 0xFF00) + pix];
i_b = vid_colormap[(light[2] & 0xFF00) + pix];
/* get color component for each component */
b_r = d_8to24table[i_r * 4 + 0];
b_g = d_8to24table[i_g * 4 + 1];
b_b = d_8to24table[i_b * 4 + 2];
b_r = d_8to24table[pix * 4 + 0];
b_g = d_8to24table[pix * 4 + 1];
b_b = d_8to24table[pix * 4 + 2];
/* scale by light */
b_r = vid_lightmap[(light[0] & 0xFF00) + b_r];
b_g = vid_lightmap[(light[1] & 0xFF00) + b_g];
b_b = vid_lightmap[(light[2] & 0xFF00) + b_b];
/* convert back to indexed color */
b_r = ( b_r >> 3 ) & 31;

View file

@ -40,6 +40,7 @@ static int swap_current = 0;
espan_t *vid_polygon_spans = NULL;
pixel_t *vid_colormap = NULL;
pixel_t *vid_alphamap = NULL;
byte *vid_lightmap = NULL;
static int vid_minu, vid_minv, vid_maxu, vid_maxv;
static int vid_zminu, vid_zminv, vid_zmaxu, vid_zmaxv;
@ -512,6 +513,14 @@ RE_Shutdown (void)
free (vid_colormap);
vid_colormap = NULL;
}
/* free lightmap */
if (vid_lightmap)
{
free (vid_lightmap);
vid_lightmap = NULL;
}
R_UnRegister ();
Mod_FreeAll ();
R_ShutdownImages ();
@ -1754,8 +1763,10 @@ Draw_GetPalette (void)
{
byte *pal, *out;
int i;
int white = 0;
// get the palette and colormap
/* get the palette and colormap */
LoadPCX ("pics/colormap.pcx", &vid_colormap, &pal, NULL, NULL);
if (!vid_colormap)
ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx");
@ -1773,9 +1784,30 @@ Draw_GetPalette (void)
out[0] = r;
out[1] = g;
out[2] = b;
if (r == 255 && g == 255 && b == 255)
white = i;
}
free (pal);
R_Printf(PRINT_ALL,"white color in palete: %d\n", white);
/* generate lightmap */
vid_lightmap = malloc(64 * 256 * sizeof(byte));
for (i=0; i < 64; i++)
{
int j, scale;
scale = (
d_8to24table[vid_colormap[i * 256 + white] * 4 + 0] +
d_8to24table[vid_colormap[i * 256 + white] * 4 + 1] +
d_8to24table[vid_colormap[i * 256 + white] * 4 + 2]
) / 3;
for(j=0; j < 256; j++)
vid_lightmap[i * 256 + j] = (j * scale) / 255;
}
}
/*