From d1a8c1b27783f8814bae1c6e5c59b74c0f99efdf Mon Sep 17 00:00:00 2001 From: Johnny Date: Mon, 3 Feb 2014 05:04:11 -0200 Subject: [PATCH] Color swizzle & software lighting fix --- libs/video/renderer/sw32/sw32_rsurf.c | 34 ++++++++++++++-------- libs/video/renderer/sw32/vid_common_sw32.c | 22 ++++++++++---- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/libs/video/renderer/sw32/sw32_rsurf.c b/libs/video/renderer/sw32/sw32_rsurf.c index 4ffe08354..9badf0c96 100644 --- a/libs/video/renderer/sw32/sw32_rsurf.c +++ b/libs/video/renderer/sw32/sw32_rsurf.c @@ -193,20 +193,30 @@ R_BuildLightMap (void) if (surf->dlightframe == r_framecount) R_AddDynamicLights (); -// // LordHavoc: changed to positive (not inverse) lighting -// for (i = 0; i < size; i++) { -// t = bound(256, blocklights[i] >> (8 - VID_CBITS), -// 256 * (VID_GRADES - 1)); -// blocklights[i] = t; -// } - // bound, invert, and shift - for (i = 0; i < size; i++) { - t = (255 * 256 - blocklights[i]) >> (8 - VID_CBITS); + /* + * JohnnyonFlame: + * 32 and 16bpp modes uses the positive lighting, unlike 8bpp + */ + switch (sw32_r_pixbytes) { + case 1: + // bound, invert, and shift + for (i = 0; i < size; i++) { + t = (255 * 256 - blocklights[i]) >> (8 - VID_CBITS); - if (t < (1 << 6)) - t = (1 << 6); + if (t < (1 << 6)) + t = (1 << 6); - blocklights[i] = t; + blocklights[i] = t; + } + break; + default: + // LordHavoc: changed to positive (not inverse) lighting + for (i = 0; i < size; i++) { + t = bound(256, blocklights[i] >> (8 - VID_CBITS), + 256 * (VID_GRADES - 1)); + blocklights[i] = t; + } + break; } } diff --git a/libs/video/renderer/sw32/vid_common_sw32.c b/libs/video/renderer/sw32/vid_common_sw32.c index e1e8d3886..279ee08d6 100644 --- a/libs/video/renderer/sw32/vid_common_sw32.c +++ b/libs/video/renderer/sw32/vid_common_sw32.c @@ -55,31 +55,41 @@ VID_MakeColormap32 (void *outcolormap, byte *pal) int c, l; byte *out; out = (byte *)&d_8to24table; + + /* + * Generates colors not affected by lighting, such as + * HUD pieces and general sprites (such as explosions) + */ for (c = 0; c < 256; c++) { - *out++ = pal[c*3+0]; - *out++ = pal[c*3+1]; *out++ = pal[c*3+2]; + *out++ = pal[c*3+1]; + *out++ = pal[c*3+0]; *out++ = 255; } d_8to24table[255] = 0; // 255 is transparent out = (byte *) outcolormap; + + /* + * Generates colors affected by lighting, such as the + * world and other models that give it life, like foes and pickups. + */ for (l = 0;l < VID_GRADES;l++) { for (c = 0;c < vid.fullbright;c++) { - out[(l*256+c)*4+0] = bound(0, (pal[c*3+0] * l) >> (VID_CBITS - 1), + out[(l*256+c)*4+0] = bound(0, (pal[c*3+2] * l) >> (VID_CBITS - 1), 255); out[(l*256+c)*4+1] = bound(0, (pal[c*3+1] * l) >> (VID_CBITS - 1), 255); - out[(l*256+c)*4+2] = bound(0, (pal[c*3+2] * l) >> (VID_CBITS - 1), + out[(l*256+c)*4+2] = bound(0, (pal[c*3+0] * l) >> (VID_CBITS - 1), 255); out[(l*256+c)*4+3] = 255; } for (;c < 255;c++) { - out[(l*256+c)*4+0] = pal[c*3+0]; + out[(l*256+c)*4+0] = pal[c*3+2]; out[(l*256+c)*4+1] = pal[c*3+1]; - out[(l*256+c)*4+2] = pal[c*3+2]; + out[(l*256+c)*4+2] = pal[c*3+0]; out[(l*256+c)*4+3] = 255; } out[(l*256+255)*4+0] = 0;