- fixed use of brightmaps.

Due to the blending they are essentially inactive on translucent content and Duke Nukem heavily abuses this.
This commit is contained in:
Christoph Oelckers 2019-11-15 20:51:02 +01:00
parent 3e0075a34d
commit dc60c7f72e
7 changed files with 44 additions and 6 deletions

View file

@ -546,14 +546,14 @@ bool ReadStatistics()
sjson_node* root = sjson_decode(ctx, (const char*)text.Data());
LevelName = sjson_get_string(root, "levelname", "");
StartEpisode = sjson_get_int(root, "episode", -1);
StartEpisode = sjson_get_string(root, "episode", "");
StartSkill = sjson_get_int(root, "skill", -1);
sjson_node* levels = sjson_find_member(root, "levels");
if (LevelName.Len() == 0 || StartEpisode == -1 || StartSkill == -1 || levels == nullptr)
if (LevelName.Len() == 0 || StartEpisode.Len() == 0 || StartSkill == -1 || levels == nullptr)
{
sjson_destroy_context(ctx);
return false;
return true; // do not error out on this.
}
int numlevels = sjson_child_count(levels);

View file

@ -1,5 +1,6 @@
#pragma once
#include <algorithm>
#include <stdint.h>
struct PalEntry
@ -34,6 +35,11 @@ struct PalEntry
return (r * 77 + g * 143 + b * 37) >> 8;
}
int Amplitude() const
{
return std::max(r, std::max(g, b));
}
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
{
int v = (r + g + b);

View file

@ -145,6 +145,25 @@ unsigned PaletteManager::FindPalswap(const uint8_t* paldata, palette_t &fadecolo
pd.lookup = paldata;
pd.crc32 = crc32;
pd.swaptexture = nullptr;
memset(pd.brightcolors, 0, 256);
pd.isbright = false;
for (int i = 0; i < 255; i++)
{
int firstmap = paldata[i];
int lastmap = paldata[i + 256 * (numshades - 2)];
PalEntry color1 = palettes[palettemap[0]].colors[firstmap];
PalEntry color2 = palettes[palettemap[0]].colors[lastmap];
int lum1 = color1.Amplitude();
int lum2 = color2.Amplitude();
if (lum1 > 40 && lum2 * 10 >= lum1 * 9)
{
pd.brightcolors[i] = 255;
pd.isbright = true;
}
}
if (fadecolor.f == 0)
{
@ -288,13 +307,18 @@ int PaletteManager::LookupPalette(int palette, int palswap, bool brightmap)
}
else
{
if (!swapdata->isbright)
{
swappedpalmap.Insert(combined, -1);
return -1;
}
bool found = false;
memset(swappedpalette, 0, sizeof(swappedpalette));
for (int i = 0; i < 255; i++)
{
int swapi = swapdata->lookup[i];
auto swapc = paldata->colors[swapi];
if (swapc.a)
int swapi = swapdata->brightcolors[i];
if (swapi)
{
found = true;
swappedpalette[i] = 0xffffffff;

View file

@ -258,6 +258,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
BindTexture(4, htex, SamplerRepeat);
}
}
#if 1
if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap])
{
if (TextureType == TT_HICREPLACE)
@ -293,6 +294,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
}
}
}
#endif
}
else return false;

View file

@ -226,6 +226,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
if (activeShader == polymostShader)
{
if (istrans) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all.
renderState.Apply(polymostShader);
if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1])
{
@ -400,6 +401,7 @@ void GLInstance::SetCull(int type, int winding)
void GLInstance::SetColor(float r, float g, float b, float a)
{
glVertexAttrib4f(2, r, g, b, a);
istrans = (a != 1);
}
void GLInstance::SetDepthFunc(int func)

View file

@ -37,9 +37,11 @@ struct PalShade
struct PalswapData
{
int32_t crc32;
bool isbright;
const uint8_t *lookup; // points to the original data. This is static so no need to copy
FHardwareTexture* swaptexture;
PalEntry fadeColor;
uint8_t brightcolors[255];
};
enum
@ -198,6 +200,7 @@ class GLInstance
FTexture* currentTexture = nullptr;
int TextureType;
int MatrixChange = 0;
bool istrans = false;
IVertexBuffer* LastVertexBuffer = nullptr;
int LastVB_Offset[2] = {};

View file

@ -1,5 +1,6 @@
// Windows layer-independent code
#define NOMINMAX
#include <Windows.h>
#include "compat.h"
#include "build.h"