From aa7af0711a247bd6ff836a3907c7b115abe956df Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 10 Jan 2022 19:11:41 +0100 Subject: [PATCH] - fine tuning of the new light modes. --- source/core/rendering/scene/hw_drawinfo.h | 2 +- source/core/rendering/scene/hw_lighting.cpp | 22 ++++----------------- source/core/rendering/scene/hw_setcolor.cpp | 22 ++++++++++++--------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/source/core/rendering/scene/hw_drawinfo.h b/source/core/rendering/scene/hw_drawinfo.h index d3e5ed82c..8d8a3acc5 100644 --- a/source/core/rendering/scene/hw_drawinfo.h +++ b/source/core/rendering/scene/hw_drawinfo.h @@ -138,7 +138,7 @@ private: int CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor); PalEntry CalcLightColor(int light, PalEntry pe, int blendfactor); void SetShaderLight(FRenderState& state, float level, float olight); - void SetFog(FRenderState& state, int lightlevel, int rellight, bool fullbright, const FColormap* cmap, bool isadditive); + void SetFog(FRenderState& state, int lightlevel, float visibility, bool fullbright, const FColormap* cmap, bool isadditive); float GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor); diff --git a/source/core/rendering/scene/hw_lighting.cpp b/source/core/rendering/scene/hw_lighting.cpp index 805df15f4..f1d310867 100644 --- a/source/core/rendering/scene/hw_lighting.cpp +++ b/source/core/rendering/scene/hw_lighting.cpp @@ -43,26 +43,12 @@ CUSTOM_CVAR(Int, gl_distfog, 70, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { for (int i = 0; i < 256; i++) { + int l = i >> 1; + if (i < 64) l = -32 + i; - if (i < 164) - { - distfogtable[0][i] = (float)((gl_distfog >> 1) + (gl_distfog)*(164 - i) / 164); - } - else if (i < 230) - { - distfogtable[0][i] = (float)((gl_distfog >> 1) - (gl_distfog >> 1)*(i - 164) / (230 - 164)); - } - else distfogtable[0][i] = 0; + distfogtable[0][i] = (float)((gl_distfog >> 1) + (gl_distfog)*(164 - l) / 164); - if (i < 128) - { - distfogtable[1][i] = 6.f + (float)((gl_distfog >> 1) + (gl_distfog)*(128 - i) / 48); - } - else if (i < 216) - { - distfogtable[1][i] = (216.f - i) / ((216.f - 128.f)) * gl_distfog / 10; - } - else distfogtable[1][i] = 0; + distfogtable[1][i] = 5.f + (float)((gl_distfog >> 1) + (float)((gl_distfog)*(128 - (i >> 1)) / 70)); } } diff --git a/source/core/rendering/scene/hw_setcolor.cpp b/source/core/rendering/scene/hw_setcolor.cpp index 1de7ebb96..aca090672 100644 --- a/source/core/rendering/scene/hw_setcolor.cpp +++ b/source/core/rendering/scene/hw_setcolor.cpp @@ -93,7 +93,7 @@ void HWDrawInfo::SetShaderLight(FRenderState &state, float level, float olight) // //========================================================================== -void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive) +void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, float visibility, bool fullbright, const FColormap *cmap, bool isadditive) { PalEntry fogcolor; float fogdensity; @@ -101,7 +101,7 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool if (cmap != nullptr && !fullbright) { fogcolor = cmap->FadeColor; - fogdensity = GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor); + fogdensity = GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor) * visibility; fogcolor.a = 0; } else @@ -160,16 +160,20 @@ void SetLightAndFog(HWDrawInfo* di, FRenderState& state, PalEntry fade, int pale if (!di->isBuildSoftwareLighting() && !foggy) { - bool fullbright = ShadeDiv < 1 / 1000.f; + bool fullbright = ShadeDiv < 1 / 1000.f || g_visibility == 0; float inverselight = shade * 255.f / numshades; - if (fullbright) inverselight /= ShadeDiv; - int vislight = 10 - sizeToBits(int(visibility)); - int gvis = -sizeToBits(g_visibility) * 2; - int rellight = 10 - sizeToBits(g_visibility + g_relvisibility) - gvis; + if (inverselight < 0) fullbright = true; + if (!fullbright) inverselight /= ShadeDiv; int lightlevel = !fullbright ? clamp(int(255 - inverselight), 0, 255) : 255; + + int rellight = 0; + if (g_relvisibility) + { + rellight = sizeToBits(g_visibility) - sizeToBits(g_visibility + g_relvisibility); + } FColormap cm = { 0xffffffff }; - di->SetColor(state, lightlevel, rellight, fullbright, cm, alpha); - di->SetFog(state, lightlevel/2 + gvis + vislight, rellight, fullbright, &cm, false); + di->SetColor(state, lightlevel, 32*rellight, fullbright, cm, alpha); + di->SetFog(state, lightlevel, visibility * g_visibility * (1.f/512.f), fullbright, &cm, false); return; } // Fog must be done before the texture so that the texture selector can override it.