diff --git a/source/build/include/palette.h b/source/build/include/palette.h index 4068a03ff..06c6d58e0 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -53,6 +53,7 @@ struct LookupTable { FString Shades; PalEntry FadeColor = 0; + float ShadeFactor = 1.f; float Visibility = 0; bool hasBrightmap = false; bool noFloorPal = false; diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index ea6104178..d7878570d 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -139,10 +139,11 @@ void LookupTableInfo::postLoadTables(void) bool isbright = false; if (divider > 0.9) { - shadediv[j] = 1 / 10000.f; // this translation is fullbright. + tables[j].ShadeFactor = 1 / 10000.f; // this translation is fullbright. } else { + if (tables[j].ShadeFactor == 0) tables[j].ShadeFactor = 1.f; // Fullbright lookups do not need brightmaps. auto fog = tables[j].FadeColor; if (GPalette.HasGlobalBrightmap && fog.r == 0 && fog.g == 0 && fog.b == 0) diff --git a/source/exhumed/src/light.cpp b/source/exhumed/src/light.cpp index f04f91fc6..469cdf843 100644 --- a/source/exhumed/src/light.cpp +++ b/source/exhumed/src/light.cpp @@ -100,9 +100,9 @@ int LoadPaletteLookups() #ifdef USE_OPENGL // These 3 tables do not have normal gradients. The others work without adjustment. // Other changes than altering the fog gradient are not necessary. - shadediv[kPalTorch] = shadediv[kPalTorch2] = 1 / 20.f; - shadediv[kPalNoTorch] = shadediv[kPalNoTorch2] = 0.25f; - shadediv[kPalBrite] = shadediv[kPalBrite] = 1 / 128.f; + lookups.tables[kPalTorch].ShadeFactor = lookups.tables[kPalTorch2].ShadeFactor = (numshades - 2) / 20.f; + lookups.tables[kPalNoTorch].ShadeFactor = lookups.tables[kPalNoTorch2].ShadeFactor = (numshades - 2) / 4.f; + lookups.tables[kPalBrite].ShadeFactor = lookups.tables[kPalBrite].ShadeFactor = (numshades - 2) / 128.f; #endif } diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index f8a25e49f..9ec37bcf8 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -60,8 +60,6 @@ F2DDrawer twodpsp; static int BufferLock = 0; -float shadediv[MAXPALOOKUPS]; - static int blendstyles[] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; static int renderops[] = { GL_FUNC_ADD, GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT }; int depthf[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL }; @@ -303,7 +301,7 @@ void GLInstance::SetPalette(int index) void GLInstance::SetPalswap(int index) { palmanager.BindPalswap(index); - renderState.ShadeDiv = shadediv[index] == 0 ? 1.f / (numshades - 2) : shadediv[index]; + renderState.ShadeDiv = lookups.tables[index].ShadeFactor; } void GLInstance::DrawImGui(ImDrawData* data) @@ -522,7 +520,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping; shader->Flags.Set(Flags); shader->Shade.Set(Shade); - shader->ShadeDiv.Set(ShadeDiv); + shader->ShadeDiv.Set(ShadeDiv / (numshades - 2)); shader->VisFactor.Set(VisFactor); shader->Flags.Set(Flags); shader->NPOTEmulationFactor.Set(NPOTEmulationFactor); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 82de2709a..daec0748b 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -89,7 +89,6 @@ enum EWinding struct ImDrawData; struct palette_t; -extern float shadediv[256]; enum {