diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 83cd3b0b3..c4e0b6c05 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -1322,30 +1322,6 @@ static int get_screen_coords(const vec2_t &p1, const vec2_t &p2, return 1; } - - -////////// *WALLSCAN HELPERS ////////// - -#define WSHELPER_DECL inline //ATTRIBUTE((always_inline)) - -static WSHELPER_DECL void tweak_tsizes(vec2_16_t *tsiz) -{ - if (pow2long[picsiz[globalpicnum]&15] == tsiz->x) - tsiz->x--; - else - tsiz->x = -tsiz->x; - - if (pow2long[picsiz[globalpicnum]>>4] == tsiz->y) - tsiz->y = (picsiz[globalpicnum]>>4); - else - tsiz->y = -tsiz->y; -} - - -static int32_t drawing_sprite = 0; - - - // // wallfront (internal) // @@ -1472,31 +1448,6 @@ static inline void wallmosts_finish(int16_t *mostbuf, int32_t z1, int32_t z2, mostbuf[ix2] = clamp(mostbuf[ix2], 0, ydimen); } -#ifdef CLASSIC_Z_DIFF_64 -typedef int64_t zint_t; - -// For drawvox() -static FORCE_INLINE zint_t mulscale16z(int32_t a, int32_t d) -{ - return ((zint_t)a * d)>>16; -} - -static FORCE_INLINE zint_t mulscale20z(int32_t a, int32_t d) -{ - return ((zint_t)a * d)>>20; -} - -static FORCE_INLINE zint_t dmulscale24z(int32_t a, int32_t d, int32_t S, int32_t D) -{ - return (((zint_t)a * d) + ((zint_t)S * D)) >> 24; -} -#else -typedef int32_t zint_t; -# define mulscale16z mulscale16 -# define mulscale20z mulscale20 -# define dmulscale24z dmulscale24 -#endif - // globalpicnum --> globalxshift, globalyshift static void calc_globalshifts(void) { diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 4b5005aa7..27beefd13 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -406,6 +406,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } static int32_t skyzbufferhack_pass = 0; + if (flatskyrender && skyzbufferhack_pass == 0) { polymost_flatskyrender(dpxy, n, method|DAMETH_SKY, tilesize); @@ -1876,6 +1877,8 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i flatskyrender = 0; vec2f_t xys[8]; + auto f = GLInterface.useMapFog; + GLInterface.useMapFog = false; // Transform polygon to sky coordinates for (int i = 0; i < n; i++) { @@ -2065,6 +2068,7 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i GLInterface.SetClamp(0); flatskyrender = 1; + GLInterface.useMapFog = f; } static void polymost_drawalls(int32_t const bunch) diff --git a/source/core/rendering/v_video.h b/source/core/rendering/v_video.h index 6d9948c96..58b52055e 100644 --- a/source/core/rendering/v_video.h +++ b/source/core/rendering/v_video.h @@ -151,7 +151,6 @@ inline bool V_IsTrueColor() class FTexture; -struct FColormap; class FileWriter; enum FTextureFormat : uint32_t; class FModelRenderer; diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index 1fd5fbfbf..0abd6c2a3 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -27,6 +27,7 @@ enum PRSFlags RF_NPOTEmulation = 32, RF_ShadeInterpolate = 64, RF_FogDisabled = 128, + RF_MapFog = 256, // RRRA E2L1. RF_HICTINT_Grayscale = 0x10000, RF_HICTINT_Invert = 0x20000, diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index ba666fea4..cd75d4904 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -196,10 +196,12 @@ static GLint primtypes[] = void GLInstance::Draw(EDrawType type, size_t start, size_t count) { + applyMapFog(); renderState.vindex = start; renderState.vcount = count; renderState.primtype = type; rendercommands.Push(renderState); + clearMapFog(); SetIdentityMatrix(Matrix_Texture); SetIdentityMatrix(Matrix_Detail); renderState.StateFlags &= ~(STF_CLEARCOLOR | STF_CLEARDEPTH | STF_VIEWPORTSET | STF_SCISSORSET); @@ -209,6 +211,7 @@ void GLInstance::DrawElement(EDrawType type, size_t start, size_t count, Polymos { if (activeShader == polymostShader) { + glVertexAttrib4fv(2, renderState.Color); glVertexAttrib4fv(2, renderState.Color); if (renderState.Color[3] != 1.f) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. renderState.Apply(polymostShader, lastState); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index cd62fb181..cdab778d0 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -480,7 +480,26 @@ public: else renderState.Flags &= ~RF_FogDisabled; } - void SetBrightness(int brightness) + // Hack... + bool useMapFog = false; + + void SetMapFog(bool yes) + { + useMapFog = yes; + } + + void applyMapFog() + { + if (useMapFog) renderState.Flags |= RF_MapFog; + else renderState.Flags &= ~RF_MapFog; + } + + void clearMapFog() + { + renderState.Flags &= ~RF_MapFog; + } + + void SetBrightness(int brightness) { renderState.Brightness = 8.f / (brightness + 8.f); } diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index 2f6d53a6c..df27271be 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "cmdlib.h" #include "v_2ddrawer.h" #include "secrets.h" +#include "glbackend/glbackend.h" BEGIN_RR_NS @@ -2518,72 +2519,7 @@ void G_FreeMapState(int levelNum) void G_SetFog(int fogtype) { - static int oldFogType = 0; - static int makeTables = 0; - static char *lut0,*lut30,*lut33,*lut23,*lut8; -#ifdef USE_OPENGL - static palette_t flut0,flut30,flut33,flut23,flut8; -#endif - if (!makeTables) - { - makeTables = 1; - lut0 = palookup[0]; - lut30 = palookup[30]; - lut33 = palookup[33]; - lut23 = palookup[23]; - lut8 = palookup[8]; -#ifdef USE_OPENGL - flut0 = palookupfog[0]; - flut30 = palookupfog[30]; - flut33 = palookupfog[33]; - flut23 = palookupfog[23]; - flut8 = palookupfog[8]; -#endif - paletteMakeLookupTable(50, NULL, 12*4, 12*4, 12*4, 0); - paletteMakeLookupTable(51, NULL, 12*4, 12*4, 12*4, 0); - } - if (fogtype == 0) - { - palookup[0] = lut0; - palookup[30] = lut30; - palookup[33] = lut33; - palookup[23] = lut23; - palookup[8] = lut8; -#ifdef USE_OPENGL - palookupfog[0] = flut0; - palookupfog[30] = flut30; - palookupfog[33] = flut33; - palookupfog[23] = flut23; - palookupfog[8] = flut8; -#endif - } - else if (fogtype == 2) - { - palookup[0] = palookup[50]; - palookup[30] = palookup[51]; - palookup[33] = palookup[51]; - palookup[23] = palookup[51]; - palookup[8] = palookup[54]; -#ifdef USE_OPENGL - palookupfog[0] = palookupfog[50]; - palookupfog[30] = palookupfog[51]; - palookupfog[33] = palookupfog[51]; - palookupfog[23] = palookupfog[51]; - palookupfog[8] = palookupfog[54]; -#endif - } - if (oldFogType != fogtype) - { - oldFogType = fogtype; -#ifdef USE_OPENGL - if (videoGetRenderMode() >= REND_POLYMOST) - { - //gltexinvalidatetype(INVALIDATE_ALL_NON_INDEXED); - static int swaps[] = { 0, 30, 33, 23, 8 }; - uploadpalswaps(5, swaps); - } -#endif - } + GLInterface.SetMapFog(fogtype != 0); } END_RR_NS diff --git a/wadsrc/static/engine/shaders/glsl/polymost.fp b/wadsrc/static/engine/shaders/glsl/polymost.fp index 562ffc80c..f7886eaa5 100644 --- a/wadsrc/static/engine/shaders/glsl/polymost.fp +++ b/wadsrc/static/engine/shaders/glsl/polymost.fp @@ -8,6 +8,7 @@ const int RF_Brightmapping = 16; const int RF_NPOTEmulation = 32; const int RF_ShadeInterpolate = 64; const int RF_FogDisabled = 128; +const int RF_MapFog = 256; const int RF_HICTINT_Grayscale = 0x1; const int RF_HICTINT_Invert = 0x2; @@ -217,9 +218,14 @@ void main() lightcolor = clamp(lightcolor + texture(s_brightmap, v_texCoord.xy).rgb, 0.0, 1.0); } color.rgb *= lightcolor; - color.rgb += u_fogColor.rgb * shade; + if ((u_flags & RF_MapFog) == 0) color.rgb += u_fogColor.rgb * shade; } } + if ((u_flags & RF_MapFog) != 0) // fog hack for RRRA E2L1. Needs to be done better, this is gross, but still preferable to the broken original implementation. + { + float fogfactor = 0.55 + 0.3 * exp2 (-5.0*v_fogCoord); + color.rgb = vec3(0.6*(1.0-fogfactor)) + color.rgb * fogfactor;// mix(vec3(0.6), color.rgb, fogfactor); + } if (color.a < u_alphaThreshold) discard; // it's only here that we have the alpha value available to be able to perform the alpha test. color.a *= v_color.a;