- use the precalculated or script-specified fade colors, if present.

This commit is contained in:
Christoph Oelckers 2019-11-10 21:11:17 +01:00
parent 5fc81d1bd4
commit 79561ace09
6 changed files with 38 additions and 25 deletions

View file

@ -116,6 +116,7 @@ void scrLoadPLUs(void)
palookupfog[1].r = 255;
palookupfog[1].g = 255;
palookupfog[1].b = 255;
palookupfog[1].f = 1;
#endif
}

View file

@ -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;

View file

@ -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
}

View file

@ -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]);
}
}

View file

@ -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);
}
//===========================================================================

View file

@ -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);