- handle RRRA E1L2's fog in the shader instead of hacking the shade tables.

This commit is contained in:
Christoph Oelckers 2020-04-12 00:21:35 +02:00
parent ee11fba4e7
commit d46ea7481f
8 changed files with 37 additions and 118 deletions

View file

@ -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)
{

View file

@ -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)

View file

@ -151,7 +151,6 @@ inline bool V_IsTrueColor()
class FTexture;
struct FColormap;
class FileWriter;
enum FTextureFormat : uint32_t;
class FModelRenderer;

View file

@ -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,

View file

@ -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);

View file

@ -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);
}

View file

@ -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

View file

@ -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;