diff --git a/source/core/rendering/scene/hw_drawstructs.h b/source/core/rendering/scene/hw_drawstructs.h index 252a15b16..8b051fac7 100644 --- a/source/core/rendering/scene/hw_drawstructs.h +++ b/source/core/rendering/scene/hw_drawstructs.h @@ -12,6 +12,8 @@ #include "render.h" #include "matrix.h" #include "gamecontrol.h" +#include "hw_renderstate.h" +#include "hw_cvars.h" #ifdef _MSC_VER #pragma warning(disable:4244) @@ -194,7 +196,6 @@ public: void SetupLights(HWDrawInfo *di, FDynLightData &lightdata); void MakeVertices(HWDrawInfo *di, bool nosplit); - void SetLightAndFog(FRenderState& state); void SkyPlane(HWDrawInfo *di, sectortype *sector, int plane, bool allowmirror); void SkyLine(HWDrawInfo *di, sectortype *sec, walltype *line); @@ -390,3 +391,39 @@ inline void SetSpriteTranslucency(const spritetype* sprite, float& alpha, FRende } alpha *= 1.f - spriteext[sprite->owner].alpha; } + +//========================================================================== +// +// +// +//========================================================================== +extern PalEntry GlobalMapFog; +extern float GlobalFogDensity; + +__forceinline void SetLightAndFog(FRenderState& state, PalEntry fade, int palette, int shade, int visibility, float alpha, bool setcolor = true) +{ + // Fog must be done before the texture so that the texture selector can override it. + bool foggy = (GlobalMapFog || (fade & 0xffffff)); + auto ShadeDiv = lookups.tables[palette].ShadeFactor; + shade = clamp(shade, 0, numshades - 1); + // Disable brightmaps if non-black fog is used. + if (ShadeDiv >= 1 / 1000.f && foggy) + { + state.EnableFog(1); + float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); + state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); + state.SetSoftLightLevel(255); + state.SetLightParms(128.f, 1 / 1000.f); + } + else + { + state.EnableFog(0); + state.SetFog(0, 0); + state.SetSoftLightLevel(gl_fogmode != 0 && ShadeDiv >= 1 / 1000.f ? 255 - Scale(shade, 255, numshades) : 255); + state.SetLightParms(visibility, ShadeDiv / (numshades - 2)); + } + + // The shade rgb from the tint is ignored here. + state.SetColor(globalr * (1 / 255.f), globalg * (1 / 255.f), globalb * (1 / 255.f), alpha); +} + diff --git a/source/core/rendering/scene/hw_flats.cpp b/source/core/rendering/scene/hw_flats.cpp index 1f08a86e2..71a1f50e7 100644 --- a/source/core/rendering/scene/hw_flats.cpp +++ b/source/core/rendering/scene/hw_flats.cpp @@ -41,9 +41,6 @@ CVAR(Int, gl_breaksec, -1, 0) #endif -extern PalEntry GlobalMapFog; -extern float GlobalFogDensity; - //========================================================================== // // @@ -170,28 +167,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) else state.SetNormal({ 0, -1, 0 }); } - // Fog must be done before the texture so that the texture selector can override it. - bool foggy = (GlobalMapFog || (fade & 0xffffff)); - auto ShadeDiv = lookups.tables[palette].ShadeFactor; - // Disable brightmaps if non-black fog is used. - if (ShadeDiv >= 1 / 1000.f && foggy) - { - state.EnableFog(1); - float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); - state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); - state.SetSoftLightLevel(255); - state.SetLightParms(128.f, 1 / 1000.f); - } - else - { - state.EnableFog(0); - state.SetFog(0, 0); - state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(shade, 255, numshades) : 255); - state.SetLightParms(visibility, ShadeDiv / (numshades - 2)); - } - - // The shade rgb from the tint is ignored here. - state.SetColorAlpha(PalEntry(255, globalr, globalg, globalb), alpha); + SetLightAndFog(state, fade, palette, shade, visibility, alpha); if (translucent) { diff --git a/source/core/rendering/scene/hw_sprites.cpp b/source/core/rendering/scene/hw_sprites.cpp index d32bf3514..17934fac3 100644 --- a/source/core/rendering/scene/hw_sprites.cpp +++ b/source/core/rendering/scene/hw_sprites.cpp @@ -46,10 +46,6 @@ #include "hw_viewpointbuffer.h" #include "hw_voxels.h" -extern PalEntry GlobalMapFog; -extern float GlobalFogDensity; - - //========================================================================== // // @@ -114,36 +110,15 @@ void HWSprite::DrawSprite(HWDrawInfo* di, FRenderState& state, bool translucent) } // Fog must be done before the texture so that the texture selector can override it. - bool foggy = (GlobalMapFog || (fade & 0xffffff)); - auto ShadeDiv = lookups.tables[palette].ShadeFactor; // Disable brightmaps if non-black fog is used. int shade = this->shade; - PalEntry color(255, globalr, globalg, globalb); if (this->shade > numshades) // handling of SW's shadow hack using a shade of 127. { shade = sector[sprite->sectnum].floorshade; - color = 0xff000000; - } - shade = clamp(shade, 0, numshades - 1); - - if (ShadeDiv >= 1 / 1000.f && foggy && !foglayer) - { - state.EnableFog(1); - float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); - state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); - state.SetSoftLightLevel(255); - state.SetLightParms(128.f, 1 / 1000.f); - } - else - { - state.EnableFog(0); - state.SetFog(0, 0); - state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(shade, 255, numshades) : 255); - state.SetLightParms(visibility, ShadeDiv / (numshades - 2)); + state.SetColor(0, 0, 0, alpha); } - // The shade rgb from the tint is ignored here. - state.SetColorAlpha(color, alpha); + SetLightAndFog(state, fade, palette, shade, visibility, alpha, this->shade <= numshades); if (modelframe == 0) { @@ -158,15 +133,20 @@ void HWSprite::DrawSprite(HWDrawInfo* di, FRenderState& state, bool translucent) state.SetLightIndex(-1); state.Draw(DT_TriangleStrip, vertexindex, 4); - if (ShadeDiv >= 1 / 1000.f && foggy && foglayer) + if (foglayer) { - // If we get here we know that we have colored fog and no fixed colormap. - float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); - state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); - state.SetTextureMode(TM_FOGLAYER); - state.SetRenderStyle(STYLE_Translucent); - state.Draw(DT_TriangleStrip, vertexindex, 4); - state.SetTextureMode(TM_NORMAL); + bool foggy = (GlobalMapFog || (fade & 0xffffff)); + auto ShadeDiv = lookups.tables[palette].ShadeFactor; + if (ShadeDiv >= 1 / 1000.f && foggy) + { + // If we get here we know that we have colored fog and no fixed colormap. + float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); + state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); + state.SetTextureMode(TM_FOGLAYER); + state.SetRenderStyle(STYLE_Translucent); + state.Draw(DT_TriangleStrip, vertexindex, 4); + state.SetTextureMode(TM_NORMAL); + } } } else diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index b4a234023..b41ae6f2a 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -39,9 +39,6 @@ #include "flatvertices.h" #include "glbackend/glbackend.h" -extern PalEntry GlobalMapFog; -extern float GlobalFogDensity; - //========================================================================== // // Create vertices for one wall @@ -104,7 +101,7 @@ void HWWall::RenderFogBoundary(HWDrawInfo *di, FRenderState &state) if (gl_fogmode)// && !di->isFullbrightScene()) { state.EnableDrawBufferAttachments(false); - SetLightAndFog(state); + SetLightAndFog(state, fade, palette, shade, visibility, alpha); state.SetEffect(EFF_FOGBOUNDARY); state.AlphaFunc(Alpha_GEqual, 0.f); state.SetDepthBias(-1, -128); @@ -115,38 +112,6 @@ void HWWall::RenderFogBoundary(HWDrawInfo *di, FRenderState &state) } } -//========================================================================== -// -// -// -//========================================================================== - -void HWWall::SetLightAndFog(FRenderState& state) -{ - // Fog must be done before the texture so that the texture selector can override it. - bool foggy = (GlobalMapFog || (fade & 0xffffff)); - auto ShadeDiv = lookups.tables[palette].ShadeFactor; - // Disable brightmaps if non-black fog is used. - if (ShadeDiv >= 1 / 1000.f && foggy) - { - state.EnableFog(1); - float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); - state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density * hw_density); - state.SetSoftLightLevel(255); - state.SetLightParms(128.f, 1 / 1000.f); - } - else - { - state.EnableFog(0); - state.SetFog(0, 0); - state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(shade, 255, numshades) : 255); - state.SetLightParms(visibility, ShadeDiv / (numshades - 2)); - } - - // The shade rgb from the tint is ignored here. - state.SetColorAlpha(PalEntry(255, globalr, globalg, globalb), alpha); -} - //========================================================================== // // @@ -163,7 +128,7 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) // Use sphere mapping for this state.SetEffect(EFF_SPHEREMAP); - SetLightAndFog(state); + SetLightAndFog(state, fade, palette, shade, visibility, alpha, false); state.SetColor(PalEntry(25, globalr >> 1, globalg >> 1, globalb >> 1)); state.SetRenderStyle(STYLE_Add); @@ -190,7 +155,7 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) { - SetLightAndFog(state); + SetLightAndFog(state, fade, palette, shade, visibility, alpha); state.SetMaterial(texture, UF_Texture, 0, sprite == nullptr ? (flags & (HWF_CLAMPX | HWF_CLAMPY)) : CLAMP_XY, TRANSLATION(Translation_Remap + curbasepal, palette), -1); int h = (int)texture->GetDisplayHeight();