From 1c3d4b46c66e43c829ef74265401e383cf104b7e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 8 Sep 2018 13:08:04 +0200 Subject: [PATCH] - fixed the use of Doom-Legacy-style 3D floor lighting in light mode 8. Legacy used some strange blending formula to calculate its colormaps for colored 3D floor lighting, this is not available in the software lighting mode, so for these the engine has to temporarily revert to light mode 2 to render them correctly. --- src/gl/renderer/gl_lightdata.cpp | 12 ++++++------ src/gl/renderer/gl_renderstate.h | 4 ++-- src/gl/scene/gl_sprite.cpp | 2 +- src/hwrenderer/scene/hw_weapon.cpp | 2 +- src/hwrenderer/utility/hw_lighting.cpp | 26 ++++++++++++++++---------- src/hwrenderer/utility/hw_lighting.h | 4 ++-- src/v_2ddrawer.cpp | 1 + 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 7566c0f12..635e6b292 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -103,10 +103,10 @@ void gl_SetColor(int sectorlightlevel, int rellight, bool fullbright, const FCol } else { - int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon); + int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor); PalEntry pe = hw_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor); gl_RenderState.SetColorAlpha(pe, alpha, cm.Desaturation); - gl_RenderState.SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight)); + gl_RenderState.SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor); } } @@ -163,7 +163,7 @@ void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *c else if (cmap != NULL && !fullbright) { fogcolor = cmap->FadeColor; - fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity); + fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor); fogcolor.a=0; } else @@ -184,9 +184,9 @@ void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *c } else { - if (level.lightmode == 2 && fogcolor == 0) + if ((level.lightmode == 2 || (level.lightmode == 8) && cmap->BlendFactor > 0) && fogcolor == 0) { - float light = hw_CalcLightLevel(lightlevel, rellight, false); + float light = hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor); gl_SetShaderLight(light, lightlevel); } else @@ -205,7 +205,7 @@ void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *c gl_RenderState.SetFog(fogcolor, fogdensity); // Korshun: fullbright fog like in software renderer. - if (level.lightmode == 8 && level.brightfog && fogdensity != 0 && fogcolor != 0) + if (level.lightmode == 8 && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0) { gl_RenderState.SetSoftLightLevel(255); } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index e3a7615b3..c046d3f61 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -290,9 +290,9 @@ public: mGlowBottom.Set(b[0], b[1], b[2], b[3]); } - void SetSoftLightLevel(int llevel) + void SetSoftLightLevel(int llevel, int blendfactor = 0) { - if (level.lightmode == 8) mLightParms[3] = llevel / 255.f; + if (level.lightmode == 8 && blendfactor == 0) mLightParms[3] = llevel / 255.f; else mLightParms[3] = -1.f; } diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index a17241142..985286a2a 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -113,7 +113,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) if (!sprite->Colormap.FadeColor.isBlack()) { float dist=Dist2(vp.Pos.X, vp.Pos.Y, sprite->x, sprite->y); - int fogd = hw_GetFogDensity(sprite->lightlevel, sprite->Colormap.FadeColor, sprite->Colormap.FogDensity); + int fogd = hw_GetFogDensity(sprite->lightlevel, sprite->Colormap.FadeColor, sprite->Colormap.FogDensity, sprite->Colormap.BlendFactor); // this value was determined by trial and error and is scale dependent! float factor = 0.05f + exp(-fogd*dist / 62500.f); diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index b0861e8bd..8e3650310 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -190,7 +190,7 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) l.cm.ClearColor(); } - l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true); + l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true, 0); if (level.lightmode == 8 || l.lightlevel < 92) { diff --git a/src/hwrenderer/utility/hw_lighting.cpp b/src/hwrenderer/utility/hw_lighting.cpp index 04836a51c..83e2acd7d 100644 --- a/src/hwrenderer/utility/hw_lighting.cpp +++ b/src/hwrenderer/utility/hw_lighting.cpp @@ -82,13 +82,15 @@ CUSTOM_CVAR(Int,gl_fogmode,1,CVAR_ARCHIVE|CVAR_NOINITCALL) // //========================================================================== -int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon) +int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor) { int light; if (lightlevel == 0) return 0; - if ((level.lightmode & 2) && lightlevel < 192 && !weapon) + bool darklightmode = (level.lightmode & 2) || (level.lightmode == 8 && blendfactor > 0); + + if (darklightmode && lightlevel < 192 && !weapon) { if (lightlevel > 100) { @@ -126,12 +128,13 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor) { int r,g,b; - if (level.lightmode == 8) - { - return pe; - } - else if (blendfactor == 0) + if (blendfactor == 0) { + if (level.lightmode == 8) + { + return pe; + } + r = pe.r * light / 255; g = pe.g * light / 255; b = pe.b * light / 255; @@ -167,11 +170,14 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor) // //========================================================================== -float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity) +float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor) { float density; - if (level.lightmode & 4) + int lightmode = level.lightmode; + if (lightmode == 8 && blendfactor > 0) lightmode = 2; // The blendfactor feature does not work with software-style lighting. + + if (lightmode & 4) { // uses approximations of Legacy's default settings. density = level.fogdensity ? (float)level.fogdensity : 18; @@ -184,7 +190,7 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity) else if ((fogcolor.d & 0xffffff) == 0) { // case 2: black fog - if (level.lightmode != 8 && !(level.flags3 & LEVEL3_NOLIGHTFADE)) + if ((lightmode != 8 || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE)) { density = distfogtable[level.lightmode != 0][hw_ClampLight(lightlevel)]; } diff --git a/src/hwrenderer/utility/hw_lighting.h b/src/hwrenderer/utility/hw_lighting.h index 9acb1578d..94304b014 100644 --- a/src/hwrenderer/utility/hw_lighting.h +++ b/src/hwrenderer/utility/hw_lighting.h @@ -7,9 +7,9 @@ struct Colormap; -int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon); +int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor); PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor); -float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity); +float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor); bool hw_CheckFog(sector_t *frontsector, sector_t *backsector); inline int hw_ClampLight(int lightlevel) diff --git a/src/v_2ddrawer.cpp b/src/v_2ddrawer.cpp index 2bbdec8ee..a2388b65b 100644 --- a/src/v_2ddrawer.cpp +++ b/src/v_2ddrawer.cpp @@ -428,6 +428,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints, // is necessary in order to best reproduce Doom's original lighting. double fadelevel; + // The hardware renderer's light modes 0, 1 and 4 use a linear light scale which must be used here as well. Otherwise the automap gets too dark. if (vid_rendermode != 4 || (level.lightmode >= 2 && level.lightmode != 4)) { double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.));