Merge pull request #812 from 0lvin/fixes

Fixes for soft render with disabled color lighting
This commit is contained in:
Yamagi 2022-04-23 16:11:34 +02:00 committed by GitHub
commit 60b5ec3268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 102 deletions

View file

@ -94,13 +94,12 @@ typedef enum
} rserr_t; } rserr_t;
/* 64 light grades available */ /* 64 light grades available */
#define LIGHTMASK 0x3F00 #define LIGHTMASK 0xFF00
extern viddef_t vid; extern viddef_t vid;
extern pixel_t *vid_buffer; // invisible buffer extern pixel_t *vid_buffer; // invisible buffer
extern pixel_t *vid_colormap; // 256 * VID_GRADES size extern pixel_t *vid_colormap; // 256 * VID_GRADES size
extern pixel_t *vid_alphamap; // 256 * 256 translucency map 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 light_t vid_lightthreshold; // full light distance maximum
extern char shift_size; // shift size in fixed-point 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; 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 pixel_t
R_ApplyLight(pixel_t pix, const light3_t light) 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; byte b_r, b_g, b_b;
int i_c; int i_c;
light3_t light_masked;
light_masked[0] = light[0] & LIGHTMASK; light_masked[0] = light[0] & LIGHTMASK;
light_masked[1] = light[1] & LIGHTMASK; light_masked[1] = light[1] & LIGHTMASK;
@ -349,27 +350,20 @@ R_ApplyLight(pixel_t pix, const light3_t light)
if (light_masked[0] == light_masked[1] && light_masked[0] == light_masked[2]) if (light_masked[0] == light_masked[1] && light_masked[0] == light_masked[2])
return vid_colormap[pix + light_masked[0]]; return vid_colormap[pix + light_masked[0]];
/* full light, code could skip light processing */ /* get index of color component of each component */
if ((light_masked[0] | light_masked[1] | light_masked[2]) <= vid_lightthreshold) i_r = vid_colormap[light_masked[0] + pix];
return pix; i_g = vid_colormap[light_masked[1] + pix];
i_b = vid_colormap[light_masked[2] + pix];
/* get color component for each component */ /* get color component for each component */
b_r = d_8to24table[pix * 4 + 0]; b_r = d_8to24table[i_r * 4 + 0];
b_g = d_8to24table[pix * 4 + 1]; b_g = d_8to24table[i_g * 4 + 1];
b_b = d_8to24table[pix * 4 + 2]; b_b = d_8to24table[i_b * 4 + 2];
/* scale by light */ /* convert back to indexed color */
b_r = vid_lightmap[light_masked[0] + b_r]; b_r = ( b_r >> 3 ) & 31;
b_g = vid_lightmap[light_masked[1] + b_g]; b_g = ( b_g >> 2 ) & 63;
b_b = vid_lightmap[light_masked[2] + b_b]; b_b = ( b_b >> 3 ) & 31;
/*
* 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;
i_c = b_r | ( b_g << 5 ) | ( b_b << 11 ); 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; espan_t *vid_polygon_spans = NULL;
pixel_t *vid_colormap = NULL; pixel_t *vid_colormap = NULL;
pixel_t *vid_alphamap = NULL; pixel_t *vid_alphamap = NULL;
byte *vid_lightmap = NULL;
light_t vid_lightthreshold = 0; light_t vid_lightthreshold = 0;
static int vid_minu, vid_minv, vid_maxu, vid_maxv; static int vid_minu, vid_minv, vid_maxu, vid_maxv;
static int vid_zminu, vid_zminv, vid_zmaxu, vid_zmaxv; static int vid_zminu, vid_zminv, vid_zmaxu, vid_zmaxv;
@ -515,13 +514,6 @@ RE_Shutdown (void)
vid_colormap = NULL; vid_colormap = NULL;
} }
/* free lightmap */
if (vid_lightmap)
{
free (vid_lightmap);
vid_lightmap = NULL;
}
R_UnRegister (); R_UnRegister ();
Mod_FreeAll (); Mod_FreeAll ();
R_ShutdownImages (); R_ShutdownImages ();
@ -1764,8 +1756,6 @@ Draw_GetPalette (void)
{ {
byte *pal, *out; byte *pal, *out;
int i; int i;
int white = 0;
/* get the palette and colormap */ /* get the palette and colormap */
LoadPCX ("pics/colormap.pcx", &vid_colormap, &pal, NULL, NULL); LoadPCX ("pics/colormap.pcx", &vid_colormap, &pal, NULL, NULL);
@ -1785,34 +1775,9 @@ Draw_GetPalette (void)
out[0] = r; out[0] = r;
out[1] = g; out[1] = g;
out[2] = b; out[2] = b;
if (r == 255 && g == 255 && b == 255)
white = i;
} }
free (pal); 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;
}
} }
/* /*

View file

@ -65,24 +65,83 @@ R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex)
} }
/* /*
* Light apply is not required * Color light apply is not required
*/ */
static qboolean static qboolean
R_SameLight(size_t size, const light3_t lightstep, const light3_t light) R_GreyscaledLight(const light3_t light)
{ {
int i; light3_t light_masked;
if (((light[0] | light[1] | light[2]) & LIGHTMASK) > vid_lightthreshold) light_masked[0] = light[0] & LIGHTMASK;
return false; light_masked[1] = light[1] & LIGHTMASK;
light_masked[2] = light[2] & LIGHTMASK;
for (i=0; i<3; i++) if (light_masked[0] == light_masked[1] && light_masked[0] == light_masked[2])
return light_masked[0];
return LIGHTMASK;
}
static void
R_DrawSurfaceBlock_Light (pixel_t *prowdest, pixel_t *psource, size_t size,
int level, light3_t lightleft, light3_t lightright)
{ {
if (((size * lightstep[i] + light[i]) & LIGHTMASK) > vid_lightthreshold) int light_masked_right, light_masked_left;
return false;
light_masked_right = R_GreyscaledLight(lightright);
if (light_masked_right != LIGHTMASK)
{
light_masked_left = R_GreyscaledLight(lightleft);
} }
return true;
// Full same light from both side
if (light_masked_right != LIGHTMASK && light_masked_left == light_masked_right)
{
pixel_t *dest, *dest_max, *src;
dest = prowdest;
dest_max = prowdest + size;
src = psource;
while (dest < dest_max)
{
*dest = vid_colormap[*src + light_masked_right];
dest++;
src++;
} }
return;
}
// same color light shades
{
int b, j;
light3_t lightstep, light;
for(j=0; j<3; j++)
{
int lighttemp;
lighttemp = lightleft[j] - lightright[j];
lightstep[j] = lighttemp >> level;
}
memcpy(light, lightright, sizeof(light3_t));
for (b=(size-1); b>=0; b--)
{
pixel_t pix;
pix = psource[b];
prowdest[b] = R_ApplyLight(pix, light);
for(j=0; j<3; j++)
light[j] += lightstep[j];
}
}
}
/* /*
================ ================
R_DrawSurfaceBlock8_anymip R_DrawSurfaceBlock8_anymip
@ -92,7 +151,7 @@ static void
R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes) R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes)
{ {
int v, i, size; int v, i, size;
unsigned char *psource, *prowdest; pixel_t *psource, *prowdest;
size = 1 << level; size = 1 << level;
psource = pbasesource; psource = pbasesource;
@ -115,38 +174,9 @@ R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes)
for (i=0 ; i<size ; i++) for (i=0 ; i<size ; i++)
{ {
light3_t lightstep, light;
int j; int j;
for(j=0; j<3; j++) R_DrawSurfaceBlock_Light(prowdest, psource, size, level, lightleft, lightright);
{
int lighttemp;
lighttemp = lightleft[j] - lightright[j];
lightstep[j] = lighttemp >> level;
}
memcpy(light, lightright, sizeof(light3_t));
if (R_SameLight(size, lightstep, light))
{
/* just copy without light apply */
memcpy(prowdest, psource, size * sizeof(pixel_t));
}
else
{
int b;
for (b=(size-1); b>=0; b--)
{
pixel_t pix;
pix = psource[b];
prowdest[b] = R_ApplyLight(pix, light);
for(j=0; j<3; j++)
light[j] += lightstep[j];
}
}
psource += sourcetstep; psource += sourcetstep;