From 78be8f866b1b8b81a656467b96333381baef1498 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 20 Sep 2020 20:39:11 +0200 Subject: [PATCH] - always use the containing sector's fog when rendering sprites. This is for consistency, otherwise sprites with a palette translation would stand out. Also use shade dependent fog density instead of a single global value. Currently this only has an effect in true color rendering mode. --- source/build/src/engine.cpp | 4 ++-- source/build/src/mdsprite.cpp | 1 + source/build/src/polymost.cpp | 16 +++++++++------- source/build/src/voxmodel.cpp | 5 +++-- source/core/palette.h | 10 +++++----- source/glbackend/glbackend.cpp | 26 ++++++++++++++++++++------ source/glbackend/glbackend.h | 1 + 7 files changed, 41 insertions(+), 22 deletions(-) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 7be582938..560bcd6b4 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -179,7 +179,7 @@ fixed_t qglobalhoriz; float fglobalposx, fglobalposy, fglobalposz; int16_t globalang, globalcursectnum; fixed_t qglobalang; -int32_t globalpal, cosglobalang, singlobalang; +int32_t globalpal, globalfloorpal, cosglobalang, singlobalang; int32_t cosviewingrangeglobalang, sinviewingrangeglobalang; int32_t xyaspect; @@ -1768,7 +1768,7 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang) globalorientation = (int32_t)sec->floorstat; if ((globalorientation&1) != 0) continue; - globalpal = sec->floorpal; + globalfloorpal = globalpal = sec->floorpal; globalpicnum = sec->floorpicnum; if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0; diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 17bcde053..e1bfd55cc 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1494,6 +1494,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) } #endif int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); + GLInterface.SetFade(sector[tspr->sectnum].floorpal); GLInterface.SetTexture(-1, tex, palid, CLAMP_XY); if (tspr->clipdist & TSPR_FLAGS_MDHACK) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 42df205bd..bdc40a126 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -299,7 +299,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } if (!lookups.checkTable(globalpal)) - globalpal = 0; + globalfloorpal = globalpal = 0; //Load texture (globalpicnum) setgotpic(globalpicnum); @@ -377,6 +377,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); + GLInterface.SetFade(globalfloorpal); bool success = GLInterface.SetTexture(globalpicnum, tileGetTexture(globalpicnum), palid, sampleroverride); if (!success) { @@ -1567,7 +1568,7 @@ static void polymost_drawalls(int32_t const bunch) globalpicnum = sec->floorpicnum; globalshade = sec->floorshade; - globalpal = sec->floorpal; + globalfloorpal = globalpal = sec->floorpal; globalorientation = sec->floorstat; GLInterface.SetVisibility(sectorVisibility(sectnum)); @@ -1808,7 +1809,7 @@ static void polymost_drawalls(int32_t const bunch) globalpicnum = sec->ceilingpicnum; globalshade = sec->ceilingshade; - globalpal = sec->ceilingpal; + globalfloorpal = globalpal = sec->ceilingpal; globalorientation = sec->ceilingstat; GLInterface.SetVisibility(sectorVisibility(sectnum)); @@ -2074,7 +2075,7 @@ static void polymost_drawalls(int32_t const bunch) if (((cy0 < ocy0) || (cy1 < ocy1)) && (!((sec->ceilingstat§or[nextsectnum].ceilingstat)&1))) { - globalpicnum = wal->picnum; globalshade = wal->shade; globalpal = (int32_t)((uint8_t)wal->pal); + globalpicnum = wal->picnum; globalshade = wal->shade; globalfloorpal = globalpal = (int32_t)((uint8_t)wal->pal); GLInterface.SetVisibility(sectorVisibility(sectnum)); globalorientation = wal->cstat; tileUpdatePicnum(&globalpicnum, wallnum+16384); @@ -2109,7 +2110,7 @@ static void polymost_drawalls(int32_t const bunch) xtex.u += (float)(nwal->xpanning - wal->xpanning) * xtex.d; ytex.u += (float)(nwal->xpanning - wal->xpanning) * ytex.d; } - globalpicnum = nwal->picnum; globalshade = nwal->shade; globalpal = (int32_t)((uint8_t)nwal->pal); + globalpicnum = nwal->picnum; globalshade = nwal->shade; globalfloorpal = globalpal = (int32_t)((uint8_t)nwal->pal); GLInterface.SetVisibility(sectorVisibility(sectnum)); globalorientation = nwal->cstat; tileUpdatePicnum(&globalpicnum, wallnum+16384); @@ -2150,7 +2151,7 @@ static void polymost_drawalls(int32_t const bunch) globalpicnum = (nextsectnum < 0) ? wal->picnum : wal->overpicnum; globalshade = wal->shade; - globalpal = wal->pal; + globalfloorpal = globalpal = wal->pal; GLInterface.SetVisibility(sectorVisibility(sectnum)); globalorientation = wal->cstat; tileUpdatePicnum(&globalpicnum, wallnum+16384); @@ -2670,7 +2671,7 @@ static void polymost_drawmaskwallinternal(int32_t wallIndex) GLInterface.SetVisibility(sectorVisibility(sectnum)); globalshade = (int32_t)wal->shade; - globalpal = (int32_t)((uint8_t)wal->pal); + globalfloorpal = globalpal = (int32_t)((uint8_t)wal->pal); vec2f_t s0 = { (float)(wal->x-globalposx), (float)(wal->y-globalposy) }; vec2f_t p0 = { s0.y*gcosang - s0.x*gsinang, s0.x*gcosang2 + s0.y*gsinang2 }; @@ -3043,6 +3044,7 @@ void polymost_drawsprite(int32_t snum) globalpicnum = tspr->picnum; globalshade = tspr->shade; globalpal = tspr->pal; + globalfloorpal = sector[tspr->sectnum].floorpal; globalorientation = tspr->cstat; GLInterface.SetVisibility(sectorVisibility(tspr->sectnum)); diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index e74ba36bf..59a57cecb 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1008,7 +1008,7 @@ voxmodel_t *loadkvxfrombuf(const char *kvxbuffer, int32_t length) //Draw voxel model as perfect cubes // Note: This is a hopeless mess that totally forfeits any chance of using a vertex buffer with its messy coordinate adjustments. :( -int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) +int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr) { // float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; float f, g, k0, zoff; @@ -1016,7 +1016,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack return 0; - if ((tspr->cstat&48)==32) + if ((tspr->cstat & 48) == 32) return 0; polymost_outputGLDebugMessage(3, "polymost_voxdraw(m:%p, tspr:%p)", m, tspr); @@ -1150,6 +1150,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) } GLInterface.SetPalswap(globalpal); + GLInterface.SetFade(sector[tspr->sectnum].floorpal); // The texture here is already translated. GLInterface.SetTexture(-1, htex, 0/*TRANSLATION(Translation_Remap + curbasepal, globalpal)*/, CLAMP_NOFILTER_XY, true); diff --git a/source/core/palette.h b/source/core/palette.h index 72c3e88a9..ac6e441b7 100644 --- a/source/core/palette.h +++ b/source/core/palette.h @@ -165,20 +165,20 @@ inline void videoclearFade() void videoTintBlood(int32_t r, int32_t g, int32_t b); -extern int32_t globalpal; +extern int32_t globalpal, globalfloorpal; extern void paletteLoadFromDisk(void); -typedef struct glblenddef_ +struct glblenddef_t { float alpha; uint8_t src, dst, flags; -} glblenddef_t; +}; -typedef struct glblend_ +struct glblend_t { glblenddef_t def[2]; -} glblend_t; +}; extern glblend_t const nullglblend, defaultglblend; extern glblend_t glblend[MAXBLENDTABS]; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 0e6c0f020..57c2ff7e6 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -152,7 +152,14 @@ void GLInstance::SetIdentityMatrix(int num) void GLInstance::SetPalswap(int index) { renderState.ShadeDiv = lookups.tables[index].ShadeFactor; - renderState.FogColor = lookups.getFade(index); +} + +void GLInstance::SetFade(int index) +{ + if (!hw_useindexedcolortextures) + renderState.FogColor = lookups.getFade(index); + else + renderState.FogColor = 0; } void PolymostRenderState::Apply(FRenderState& state, GLState& oldState) @@ -227,17 +234,24 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState) state.SetDepthFunc(DepthFunc); oldState.DepthFunc = DepthFunc; } + bool foggy = (GLInterface.useMapFog || FogColor); // Disable brightmaps if non-black fog is used. - if (!(Flags & RF_FogDisabled) && ShadeDiv >= 1 / 1000.f && (GLInterface.useMapFog || FogColor)) + if (!(Flags & RF_FogDisabled) && ShadeDiv >= 1 / 1000.f && foggy) { state.EnableFog(1); + float density = GLInterface.useMapFog ? 350.f : 350.f - Scale(numshades - Shade, 150, numshades); + state.SetFog((GLInterface.useMapFog) ? PalEntry(0x999999) : FogColor, density); + state.SetSoftLightLevel(255); + state.SetLightParms(128.f, 1/1000.f); + } + else + { + state.EnableFog(0); + state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(Shade, 255, numshades) : 255); + state.SetLightParms(VisFactor, ShadeDiv / (numshades - 2)); } - else state.EnableFog(0); - state.SetFog((GLInterface.useMapFog) ? PalEntry(0x999999) : FogColor, 350.f); // Fixme: The real density still needs to be implemented. 350 is a reasonable default only. - state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(Shade, 255, numshades) : 255); - state.SetLightParms(VisFactor, ShadeDiv / (numshades - 2)); state.SetTextureMode(TextureMode); state.SetNpotEmulation(NPOTEmulation.Y, NPOTEmulation.X); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 952b752f4..a3fe80ccb 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -140,6 +140,7 @@ public: } void SetPalswap(int index); + void SetFade(int palette); void SetShade(int32_t shade, int numshades) {