soft: revert to use colormap

Apply light uses colormap for each color components with colorlights.
This commit is contained in:
Denis Pauk 2022-04-17 23:07:34 +03:00
parent afc892001d
commit b2500d6aed
4 changed files with 15 additions and 60 deletions

View file

@ -94,13 +94,12 @@ typedef enum
} rserr_t;
/* 64 light grades available */
#define LIGHTMASK 0x3F00
#define LIGHTMASK 0xFF00
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 light_t vid_lightthreshold; // full light distance maximum
extern char shift_size; // shift size in fixed-point

View file

@ -586,7 +586,7 @@ R_AliasSetupLighting(entity_t *currententity)
}
}
if(r_colorlight->value < 2)
if(r_colorlight->value == 0)
{
float temp = (light[0] + light[1] + light[2]) / 3.0;

View file

@ -337,9 +337,10 @@ static byte *d_16to8table = NULL; // 16 to 8 bit conversion table
pixel_t
R_ApplyLight(pixel_t pix, const light3_t light)
{
light3_t light_masked;
pixel_t i_r, i_g, i_b;
byte b_r, b_g, b_b;
int i_c;
light3_t light_masked;
light_masked[0] = light[0] & LIGHTMASK;
light_masked[1] = light[1] & LIGHTMASK;
@ -349,30 +350,20 @@ R_ApplyLight(pixel_t pix, const light3_t light)
if (light_masked[0] == light_masked[1] && light_masked[0] == light_masked[2])
return vid_colormap[pix + light_masked[0]];
/* full light, code could skip light processing */
if ((light_masked[0] | light_masked[1] | light_masked[2]) <= vid_lightthreshold)
{
// FIXME: color conversion should be applied and based on vid_colormap
return pix;
}
/* get index of color component of each component */
i_r = vid_colormap[light_masked[0] + pix];
i_g = vid_colormap[light_masked[1] + pix];
i_b = vid_colormap[light_masked[2] + pix];
/* get color component for each component */
b_r = d_8to24table[pix * 4 + 0];
b_g = d_8to24table[pix * 4 + 1];
b_b = d_8to24table[pix * 4 + 2];
b_r = d_8to24table[i_r * 4 + 0];
b_g = d_8to24table[i_g * 4 + 1];
b_b = d_8to24table[i_b * 4 + 2];
/* scale by light */
b_r = vid_lightmap[light_masked[0] + b_r];
b_g = vid_lightmap[light_masked[1] + b_g];
b_b = vid_lightmap[light_masked[2] + b_b];
/*
* convert back to indexed color (value reshifted >> 2)
* look to R_Convert32To8bit
*/
b_r = ( b_r >> 1 ); // & 31;
b_g = ( b_g >> 0 ); // & 63;
b_b = ( b_b >> 1 ); // & 31;
/* convert back to indexed color */
b_r = ( b_r >> 3 ) & 31;
b_g = ( b_g >> 2 ) & 63;
b_b = ( b_b >> 3 ) & 31;
i_c = b_r | ( b_g << 5 ) | ( b_b << 11 );

View file

@ -40,7 +40,6 @@ 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;
light_t vid_lightthreshold = 0;
static int vid_minu, vid_minv, vid_maxu, vid_maxv;
static int vid_zminu, vid_zminv, vid_zmaxu, vid_zmaxv;
@ -515,13 +514,6 @@ RE_Shutdown (void)
vid_colormap = NULL;
}
/* free lightmap */
if (vid_lightmap)
{
free (vid_lightmap);
vid_lightmap = NULL;
}
R_UnRegister ();
Mod_FreeAll ();
R_ShutdownImages ();
@ -1764,8 +1756,6 @@ Draw_GetPalette (void)
{
byte *pal, *out;
int i;
int white = 0;
/* get the palette and colormap */
LoadPCX ("pics/colormap.pcx", &vid_colormap, &pal, NULL, NULL);
@ -1785,34 +1775,9 @@ 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;
/* full light distance maximum */
if (scale == 255)
vid_lightthreshold = i * 256;
for(j=0; j < 256; j++)
vid_lightmap[i * 256 + j] = ((j * scale / 255) >> 2) & 63;
}
}
/*