Skip to content

Commit

Permalink
- use different fade ramps for 64 and 32 shades.
Browse files Browse the repository at this point in the history
Also some optimization to eliminate redundant calculations of the fade strength.
  • Loading branch information
coelckers committed Jan 10, 2022
1 parent 07eeb14 commit aa0e558
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions source/core/gamecontrol.cpp
Expand Up @@ -145,6 +145,7 @@ void highTileSetup();
void FontCharCreated(FGameTexture* base, FGameTexture* untranslated);
void LoadVoxelModels();
void MarkMap();
void BuildFogTable();

DStatusBarCore* StatusBar;

Expand Down Expand Up @@ -1032,6 +1033,7 @@ int RunGame()
for (int i = 1; i <= 255; i++) palindexmap[i] = i;
GPalette.Init(MAXPALOOKUPS + 2, palindexmap); // one slot for each translation, plus a separate one for the base palettes and the internal one
gi->loadPalette();
BuildFogTable();
StartScreen->Progress();
InitTextures();

Expand Down
2 changes: 2 additions & 0 deletions source/core/rendering/scene/hw_drawinfo.cpp
Expand Up @@ -600,6 +600,8 @@ void HWDrawInfo::RenderPortal(HWPortal *p, FRenderState &state, bool usestencil)
auto gp = static_cast<HWPortal *>(p);
gp->SetupStencil(this, state, usestencil);
auto new_di = StartDrawInfo(this, Viewpoint, &VPUniforms);
new_di->visibility = visibility;
new_di->rellight = rellight;
new_di->mCurrentPortal = gp;
state.SetLightIndex(-1);
gp->DrawContents(new_di, state);
Expand Down
11 changes: 6 additions & 5 deletions source/core/rendering/scene/hw_lighting.cpp
Expand Up @@ -29,7 +29,7 @@
#include "hw_drawinfo.h"

// externally settable lighting properties
static float distfogtable[2][256]; // light to fog conversion table for black fog
static float distfogtable[256]; // light to fog conversion table for black fog

CVAR(Int, hw_weaponlight, 8, CVAR_ARCHIVE);

Expand All @@ -39,15 +39,16 @@ CVAR(Int, hw_weaponlight, 8, CVAR_ARCHIVE);
//
//==========================================================================

CUSTOM_CVAR(Int, gl_distfog, 70, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
void BuildFogTable()
{
const int gl_distfog = 70;
for (int i = 0; i < 256; i++)
{
int l = i >> 1;
if (i < 64) l = -32 + i;

distfogtable[0][i] = (float)((gl_distfog >> 1) + (gl_distfog)*(164 - l) / 164);
distfogtable[1][i] = 5.f + (float)((gl_distfog >> 1) + (float)((gl_distfog)*(128 - (i >> 1)) / 70));
if (numshades == 64) distfogtable[i] = (float)((gl_distfog >> 1) + (gl_distfog)*(164 - l) / 164);
else distfogtable[i] = 5.f + (float)((gl_distfog >> 1) + (float)((gl_distfog)*(128 - (i >> 1)) / 70));
}
}

Expand Down Expand Up @@ -139,7 +140,7 @@ float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfog
else if ((fogcolor.d & 0xffffff) == 0)
{
// case 2: black fog
density = distfogtable[hw_lightmode != 1][hw_ClampLight(lightlevel)];
density = distfogtable[hw_ClampLight(lightlevel)];
}
#if 0
else if (Level->outsidefogdensity != 0 && APART(Level->info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (Level->info->outsidefog & 0xffffff))
Expand Down

0 comments on commit aa0e558

Please sign in to comment.