- move brightmap handling to the common code.

# Conflicts:
#	source/common/utility/basics.h

# Conflicts:
#	source/build/src/palette.cpp
This commit is contained in:
Christoph Oelckers 2020-04-12 08:21:08 +02:00
parent ae6403a205
commit b8a289bf61
6 changed files with 56 additions and 29 deletions

View file

@ -54,7 +54,6 @@ enum
}; };
extern uint8_t curbasepal; extern uint8_t curbasepal;
extern FixedBitArray<256> FullbrightIndices;
extern int32_t r_scenebrightness; extern int32_t r_scenebrightness;
struct palette_t struct palette_t

View file

@ -39,8 +39,6 @@ palette_t palookupfog[MAXPALOOKUPS];
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked. // NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
int8_t g_noFloorPal[MAXPALOOKUPS]; int8_t g_noFloorPal[MAXPALOOKUPS];
FixedBitArray<256> FullbrightIndices;
//========================================================================== //==========================================================================
// //
// Adds a palette to the global list of base palettes // Adds a palette to the global list of base palettes
@ -155,28 +153,7 @@ void paletteLoadFromDisk(void)
void palettePostLoadTables(void) void palettePostLoadTables(void)
{ {
globalpal = 0; globalpal = 0;
GPalette.GenerateGlobalBrightmapFromColormap(paletteGetLookupTable(0), numshades);
auto lookup = paletteGetLookupTable(0);
ImageHelpers::SetPalette(GPalette.BaseColors);
for (int c = 0; c < 255; ++c) // skipping transparent color
{
uint8_t index = lookup[c];
PalEntry color = GPalette.BaseColors[index];
// don't consider black fullbright
if (color.isBlack()) continue;
bool isbright = true;
for (int i = 1; i < numshades; i++)
if (lookup[i * 256 + c] != index)
{
isbright = false;
break;
}
if (isbright) FullbrightIndices.Set(c);
}
} }
//========================================================================== //==========================================================================

View file

@ -290,7 +290,7 @@ void uploadbasepalette(int32_t basepalnum)
basepalWFullBrightInfo[i*4+0] = remap->Palette[i].b; basepalWFullBrightInfo[i*4+0] = remap->Palette[i].b;
basepalWFullBrightInfo[i*4+1] = remap->Palette[i].g; basepalWFullBrightInfo[i*4+1] = remap->Palette[i].g;
basepalWFullBrightInfo[i*4+2] = remap->Palette[i].r; basepalWFullBrightInfo[i*4+2] = remap->Palette[i].r;
basepalWFullBrightInfo[i*4+3] = 0-(FullbrightIndices[i] != 0); basepalWFullBrightInfo[i * 4 + 3] = GPalette.GlobalBrightmap.Palette[i].r; // todo: get rid of this.
} }
GLInterface.SetPaletteData(basepalnum, basepalWFullBrightInfo); GLInterface.SetPaletteData(basepalnum, basepalWFullBrightInfo);

View file

@ -53,6 +53,7 @@ FColorMatcher ColorMatcher;
void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! void PaletteContainer::Init(int numslots) // This cannot be a constructor!!!
{ {
Clear(); Clear();
HasGlobalBrightmap = false;
// Make sure that index 0 is always the identity translation. // Make sure that index 0 is always the identity translation.
FRemapTable remap; FRemapTable remap;
remap.MakeIdentity(); remap.MakeIdentity();
@ -64,15 +65,17 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!!
void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index)
{ {
// Initialize all tables to the original palette.
// At this point we do not care about the transparent index yet. // At this point we do not care about the transparent index yet.
for (int i = 0; i < 256; i++, colors += 3) for (int i = 0; i < 256; i++, colors += 3)
{ {
BaseColors[i] = PalEntry(255, colors[0], colors[1], colors[2]); uniqueRemaps[0]->Palette[i] = BaseColors[i] = RawColors[i] = PalEntry(255, colors[0], colors[1], colors[2]);
Remap[i] = i; Remap[i] = i;
} }
uniqueRemaps[0]->MakeIdentity(); // update the identity remap. uniqueRemaps[0]->MakeIdentity(); // update the identity remap.
// If the palette already has a transparent index, clear that color now
if (transparent_index >= 0 && transparent_index <= 255) if (transparent_index >= 0 && transparent_index <= 255)
{ {
BaseColors[transparent_index] = 0; BaseColors[transparent_index] = 0;
@ -85,8 +88,8 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index)
// Find white and black from the original palette so that they can be // Find white and black from the original palette so that they can be
// used to make an educated guess of the translucency % for a // used to make an educated guess of the translucency % for a
// translucency map. // translucency map.
WhiteIndex = BestColor((uint32_t*)BaseColors, 255, 255, 255, 0, 255); WhiteIndex = BestColor((uint32_t*)RawColors, 255, 255, 255, 0, 255);
BlackIndex = BestColor((uint32_t*)BaseColors, 0, 0, 0, 0, 255); BlackIndex = BestColor((uint32_t*)RawColors, 0, 0, 0, 0, 255);
} }
@ -240,6 +243,41 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap)
return AddTranslation(slot, remap); return AddTranslation(slot, remap);
} }
//===========================================================================
//
// Examines the colormap to see if some of the colors have to be
// considered fullbright all the time.
//
//===========================================================================
void PaletteContainer::GenerateGlobalBrightmapFromColormap(const uint8_t *cmapdata, int numlevels)
{
GlobalBrightmap.MakeIdentity();
memset(GlobalBrightmap.Remap, WhiteIndex, 256);
for (int i = 0; i < 256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255);
for (int j = 0; j < numlevels; j++)
{
for (int i = 0; i < 256; i++)
{
// the palette comparison should be for ==0 but that gives false positives with Heretic
// and Hexen.
uint8_t mappedcolor = cmapdata[i]; // consider colormaps which already remap the base level.
if (cmapdata[i + j * 256] != mappedcolor || (RawColors[mappedcolor].r < 10 && RawColors[mappedcolor].g < 10 && RawColors[mappedcolor].b < 10))
{
GlobalBrightmap.Remap[i] = BlackIndex;
GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0);
}
}
}
for (int i = 0; i < 256; i++)
{
HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == WhiteIndex;
if (GlobalBrightmap.Remap[i] == WhiteIndex) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i);
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
// //

View file

@ -71,10 +71,15 @@ class PaletteContainer
{ {
public: public:
PalEntry BaseColors[256]; // non-gamma corrected palette PalEntry BaseColors[256]; // non-gamma corrected palette
PalEntry RawColors[256]; // colors as read from the game data without the transparancy remap applied
uint8_t Remap[256]; // remap original palette indices to in-game indices uint8_t Remap[256]; // remap original palette indices to in-game indices
uint8_t WhiteIndex; // white in original palette index uint8_t WhiteIndex; // white in original palette index
uint8_t BlackIndex; // black in original palette index uint8_t BlackIndex; // black in original palette index
bool HasGlobalBrightmap;
FRemapTable GlobalBrightmap;
private: private:
FMemArena remapArena; FMemArena remapArena;
TArray<FRemapTable*> uniqueRemaps; TArray<FRemapTable*> uniqueRemaps;
@ -90,6 +95,7 @@ public:
void CopyTranslation(int dest, int src); void CopyTranslation(int dest, int src);
int StoreTranslation(int slot, FRemapTable* remap); int StoreTranslation(int slot, FRemapTable* remap);
FRemapTable* TranslationToTable(int translation); FRemapTable* TranslationToTable(int translation);
void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels);
void PushIdentityTable(int slot) void PushIdentityTable(int slot)
{ {

View file

@ -57,6 +57,13 @@ using INTBOOL = int;
using BITFIELD = uint32_t; using BITFIELD = uint32_t;
#if defined(_MSC_VER)
#define NOVTABLE __declspec(novtable)
#else
#define NOVTABLE
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define NOVTABLE __declspec(novtable) #define NOVTABLE __declspec(novtable)
#else #else