From 8484ba929472ec1373a087a7b5c80dd50dc87fe9 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 6 Dec 2021 20:38:30 -0500 Subject: [PATCH 1/3] Alpha value for fade colormaps --- src/r_data.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 04b6c232b..46ae0dbd2 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -615,6 +615,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb, cdestbright; double maskamt = 0, othermask = 0; + double fmaskamt = 0, fothermask = 0; UINT8 cr = R_GetRgbaR(extra_colormap->rgba), cg = R_GetRgbaG(extra_colormap->rgba), @@ -622,8 +623,8 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) ca = R_GetRgbaA(extra_colormap->rgba), cfr = R_GetRgbaR(extra_colormap->fadergba), cfg = R_GetRgbaG(extra_colormap->fadergba), - cfb = R_GetRgbaB(extra_colormap->fadergba); -// cfa = R_GetRgbaA(extra_colormap->fadergba); // unused in software + cfb = R_GetRgbaB(extra_colormap->fadergba), + cfa = R_GetRgbaA(extra_colormap->fadergba); UINT8 fadestart = extra_colormap->fadestart, fadedist = extra_colormap->fadeend - extra_colormap->fadestart; @@ -654,14 +655,11 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) cdestb = cfb; cdestbright = sqrt((cfr*cfr) + (cfg*cfg) + (cfb*cfb)); - // fade alpha unused in software - // maskamt = (double)(cfa/24.0l); - // othermask = 1 - maskamt; - // maskamt /= 0xff; + fmaskamt = (double)(cfa/24.0l); + fothermask = 1 - fmaskamt; + //fmaskamt /= 0xff; - // cdestr *= maskamt; - // cdestg *= maskamt; - // cdestb *= maskamt; + (void)fothermask; // unused, but don't feel like commenting it out ///////////////////// // This code creates the colormap array used by software renderer @@ -710,7 +708,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) } // Add/subtract this value during fading. - brightChange[i] = fabs(cbest - cdist) / (double)fadedist; + brightChange[i] = (fabs(cbest - cdist) / (double)fadedist) * fmaskamt; } // Now allocate memory for the actual colormap array itself! From b03cfe302d0850a77e36d6186ad3007eb87dc783 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 6 Dec 2021 20:58:31 -0500 Subject: [PATCH 2/3] OGL fade alpha support --- src/hardware/hw_defs.h | 2 +- src/hardware/r_opengl/r_opengl.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 3f6ad01e5..b4dc1accb 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -284,7 +284,7 @@ struct FSurfaceInfo typedef struct FSurfaceInfo FSurfaceInfo; #define GL_DEFAULTMIX 0x00000000 -#define GL_DEFAULTFOG 0xFF000000 +#define GL_DEFAULTFOG 0x19000000 //Hurdler: added for backward compatibility enum hwdsetspecialstate diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 367ce8331..51a4dd99d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -723,6 +723,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; "colorIntensity = abs(colorIntensity - (fogBrightness));\n" \ "}\n" \ "colorIntensity *= darkness;\n" \ + "colorIntensity *= fade_color.a * 10.0;\n" \ "if (abs(final_color.r - fade_color.r) <= colorIntensity) {\n" \ "final_color.r = fade_color.r;\n" \ "} else if (final_color.r < fade_color.r) {\n" \ From dbefc8fe5810d13f690c0549a1df8df1749e3bf3 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 6 Dec 2021 22:47:15 -0500 Subject: [PATCH 3/3] Fix yellow persist fade colormap bug I did the equivalent change to OpenGL and it broke Zoned City, despite it being fine in Software ... not sure what's up with that, since the color math is pretty similar. Just gonna leave that alone for now... --- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/r_data.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 51a4dd99d..84d6ded6e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -715,12 +715,12 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; "float colorBrightness = sqrt((final_color.r * final_color.r) + (final_color.g * final_color.g) + (final_color.b * final_color.b));\n" \ "float fogBrightness = sqrt((fade_color.r * fade_color.r) + (fade_color.g * fade_color.g) + (fade_color.b * fade_color.b));\n" \ "float colorIntensity = 0.0;\n" \ - "if (fogBrightness > colorBrightness) {\n" \ + "if (colorBrightness < fogBrightness) {\n" \ "colorIntensity = 1.0 - min(final_color.r, min(final_color.g, final_color.b));\n" \ - "colorIntensity = abs(colorIntensity - (1.0 - fogBrightness));\n" \ + "colorIntensity = abs(colorIntensity - (1.0 - max(fade_color.r, max(fade_color.g, fade_color.b))));\n" \ "} else {\n" \ "colorIntensity = max(final_color.r, max(final_color.g, final_color.b));\n" \ - "colorIntensity = abs(colorIntensity - (fogBrightness));\n" \ + "colorIntensity = abs(colorIntensity - min(fade_color.r, min(fade_color.g, fade_color.b)));\n" \ "}\n" \ "colorIntensity *= darkness;\n" \ "colorIntensity *= fade_color.a * 10.0;\n" \ diff --git a/src/r_data.c b/src/r_data.c index 46ae0dbd2..bb2e508ba 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -699,12 +699,12 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) if (cbrightness < cdestbright) { cbest = 255.0l - min(r, min(g, b)); - cdist = 255.0l - cdestbright; + cdist = 255.0l - max(cdestr, max(cdestg, cdestb)); } else { cbest = max(r, max(g, b)); - cdist = cdestbright; + cdist = min(cdestr, min(cdestg, cdestb)); } // Add/subtract this value during fading.