diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp index b5d2b7024..d393245d7 100644 --- a/source/blood/src/screen.cpp +++ b/source/blood/src/screen.cpp @@ -116,6 +116,7 @@ void scrLoadPLUs(void) palookupfog[1].r = 255; palookupfog[1].g = 255; palookupfog[1].b = 255; + palookupfog[1].f = 1; #endif } diff --git a/source/build/include/palette.h b/source/build/include/palette.h index f900fef6c..8bf75b49b 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -40,9 +40,10 @@ inline void SetPaletteIndexFullbright(int col) PaletteIndexFullbrights[col >> 5] |= (1u << (col & 31)); } -typedef struct { +struct palette_t +{ uint8_t r, g, b, f; -} palette_t; +}; typedef struct { uint8_t r, g, b; } rgb24_t; diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index 01701f1a9..16fedf317 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -698,6 +698,7 @@ void paletteMakeLookupTable(int32_t palnum, const char *remapbuf, uint8_t r, uin palookupfog[palnum].r = r; palookupfog[palnum].g = g; palookupfog[palnum].b = b; + palookupfog[palnum].f = 1; #endif } diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index a3a0431df..4374b6644 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -304,7 +304,7 @@ void polymost_glinit() } for (int palookupnum = 0; palookupnum < MAXPALOOKUPS; ++palookupnum) { - GLInterface.SetPalswapData(palookupnum, (uint8_t*)palookup[palookupnum], numshades+1); + GLInterface.SetPalswapData(palookupnum, (uint8_t*)palookup[palookupnum], numshades+1, palookupfog[palookupnum]); } } @@ -405,7 +405,7 @@ void uploadpalswaps(int count, int32_t* swaps) { for (int i = 0; i < count; i++) { - GLInterface.SetPalswapData(i, (uint8_t*)palookup[i], numshades + 1); + GLInterface.SetPalswapData(i, (uint8_t*)palookup[i], numshades + 1, palookupfog[i]); } } diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index c8e350ea7..30e865f82 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -41,6 +41,7 @@ #include "resourcefile.h" #include "imagehelpers.h" #include "v_font.h" +#include "palette.h" //=========================================================================== // @@ -126,7 +127,7 @@ unsigned PaletteManager::FindPalette(const uint8_t *paldata) // //=========================================================================== -unsigned PaletteManager::FindPalswap(const uint8_t* paldata) +unsigned PaletteManager::FindPalswap(const uint8_t* paldata, palette_t &fadecolor) { if (paldata == nullptr) return 0; auto crc32 = CalcCRC32(paldata, 256 * numshades); @@ -145,24 +146,31 @@ unsigned PaletteManager::FindPalswap(const uint8_t* paldata) pd.crc32 = crc32; pd.swaptexture = nullptr; - // Find what index maps to black (or the darkest available color) - int found = -1; - PalEntry foundColor = 0xffffffff; - for (int i = 0; i < 255; i++) + if (fadecolor.f == 0) { - int map = paldata[i]; - PalEntry color = palettes[palettemap[0]].colors[map]; - if (color.Luminance() < foundColor.Luminance()) + // Find what index maps to black (or the darkest available color) + int found = -1; + PalEntry foundColor = 0xffffffff; + for (int i = 0; i < 255; i++) { - foundColor = color; - found = i; + int map = paldata[i]; + PalEntry color = palettes[palettemap[0]].colors[map]; + if (color.Luminance() < foundColor.Luminance()) + { + foundColor = color; + found = i; + } } - } - // Determine the fade color. We pick what black, or the darkest color, maps to in the lowest shade level. - int map = paldata[(numshades - 2) * 256 + found]; // do not look in the latest shade level because it doesn't always contain useful data for this. - pd.fadeColor = palettes[palettemap[0]].colors[map]; - if (pd.fadeColor.Luminance() < 10) pd.fadeColor = 0; // Account for the inability to check the last fade level by using a higher threshold for determining black fog. + // Determine the fade color. We pick what black, or the darkest color, maps to in the lowest shade level. + int map = paldata[(numshades - 2) * 256 + found]; // do not look in the latest shade level because it doesn't always contain useful data for this. + pd.fadeColor = palettes[palettemap[0]].colors[map]; + if (pd.fadeColor.Luminance() < 10) pd.fadeColor = 0; // Account for the inability to check the last fade level by using a higher threshold for determining black fog. + } + else + { + pd.fadeColor = PalEntry(fadecolor.r, fadecolor.g, fadecolor.b); + } return palswaps.Push(pd); } @@ -220,11 +228,11 @@ void PaletteManager::BindPalette(int index) // //=========================================================================== -void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshades_) +void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshades_, palette_t &fadecolor) { if (index < 0 || index > 255) return; // invalid index - ignore. numshades = numshades_; - palswapmap[index] = FindPalswap(data); + palswapmap[index] = FindPalswap(data, fadecolor); } //=========================================================================== diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index c294d1120..a0b68d374 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -17,6 +17,7 @@ class SurfaceShader; class FTexture; class GLInstance; class F2DDrawer; +struct palette_t; struct PaletteData { @@ -66,7 +67,7 @@ class PaletteManager //OpenGLRenderer::GLDataBuffer* palswapBuffer = nullptr; - unsigned FindPalswap(const uint8_t* paldata); + unsigned FindPalswap(const uint8_t* paldata, palette_t& fadecolor); public: PaletteManager(GLInstance *inst_) : inst(inst_) @@ -75,7 +76,7 @@ public: void DeleteAll(); void DeleteAllTextures(); void SetPalette(int index, const uint8_t *data); - void SetPalswapData(int index, const uint8_t* data, int numshades); + void SetPalswapData(int index, const uint8_t* data, int numshades, palette_t &fadecolor); void BindPalette(int index); void BindPalswap(int index); @@ -177,6 +178,7 @@ enum ETexType }; struct ImDrawData; +struct palette_t; class GLInstance { @@ -295,9 +297,9 @@ public: palmanager.SetPalette(index, data); } - void SetPalswapData(int index, const uint8_t* data, int numshades) + void SetPalswapData(int index, const uint8_t* data, int numshades, palette_t& fadecolor) { - palmanager.SetPalswapData(index, data, numshades); + palmanager.SetPalswapData(index, data, numshades, fadecolor); } void SetPalswap(int index);