Merge branch 'master' into softwarescaling

This commit is contained in:
Rachael Alexanderson 2018-12-15 09:51:50 -05:00
commit aaabefbfab
13 changed files with 144 additions and 51 deletions

View file

@ -123,10 +123,11 @@ CUSTOM_CVAR(Bool, gl_notexturefill, false, CVAR_NOINITCALL)
CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL) CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL)
{ {
int newself = self; int newself = self;
if (newself > 4) newself = 8; // use 8 for software lighting to avoid conflicts with the bit mask if (newself > 8) newself = 16; // use 8 and 16 for software lighting to avoid conflicts with the bit mask
if (newself < 0) newself = 0; else if (newself > 4) newself = 8;
else if (newself < 0) newself = 0;
if (self != newself) self = newself; if (self != newself) self = newself;
else if ((level.info == nullptr || level.info->lightmode == -1)) level.lightmode = self; else if ((level.info == nullptr || level.info->lightmode == ELightMode::NotSet)) level.lightmode = (ELightMode)*self;
} }
@ -1522,7 +1523,7 @@ void G_InitLevelLocals ()
level.DefaultEnvironment = info->DefaultEnvironment; level.DefaultEnvironment = info->DefaultEnvironment;
level.lightmode = info->lightmode < 0? gl_lightmode : info->lightmode; level.lightmode = info->lightmode == ELightMode::NotSet? (ELightMode)*gl_lightmode : info->lightmode;
level.brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog; level.brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog;
level.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces; level.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces;
level.notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill; level.notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill;

View file

@ -314,6 +314,19 @@ struct FExitText
} }
}; };
enum class ELightMode : int8_t
{
NotSet = -1,
LinearStandard = 0,
DoomBright = 1,
Doom = 2,
DoomDark = 3,
DoomLegacy = 4,
ZDoomSoftware = 8,
DoomSoftware = 16
};
struct level_info_t struct level_info_t
{ {
int levelnum; int levelnum;
@ -395,7 +408,7 @@ struct level_info_t
TArray<FString> EventHandlers; TArray<FString> EventHandlers;
int8_t lightmode; ELightMode lightmode;
int8_t brightfog; int8_t brightfog;
int8_t lightadditivesurfaces; int8_t lightadditivesurfaces;
int8_t notexturefill; int8_t notexturefill;

View file

@ -183,7 +183,7 @@ struct FLevelLocals
float MusicVolume; float MusicVolume;
// Hardware render stuff that can either be set via CVAR or MAPINFO // Hardware render stuff that can either be set via CVAR or MAPINFO
int lightmode; ELightMode lightmode;
bool brightfog; bool brightfog;
bool lightadditivesurfaces; bool lightadditivesurfaces;
bool notexturefill; bool notexturefill;
@ -207,6 +207,21 @@ struct FLevelLocals
return savegamerestore return savegamerestore
|| (info != nullptr && info->Snapshot.mBuffer != nullptr && info->isValid()); || (info != nullptr && info->Snapshot.mBuffer != nullptr && info->isValid());
} }
bool isSoftwareLighting() const
{
return lightmode >= ELightMode::ZDoomSoftware;
}
bool isDarkLightMode() const
{
return !!((int)lightmode & (int)ELightMode::Doom);
}
void SetFallbackLightMode()
{
lightmode = ELightMode::Doom;
}
}; };
extern FLevelLocals level; extern FLevelLocals level;

View file

@ -284,7 +284,7 @@ void level_info_t::Reset()
PrecacheSounds.Clear(); PrecacheSounds.Clear();
brightfog = -1; brightfog = -1;
lightmode = -1; lightmode = ELightMode::NotSet;
notexturefill = -1; notexturefill = -1;
lightadditivesurfaces = -1; lightadditivesurfaces = -1;
skyrotatevector = FVector3(0, 0, 1); skyrotatevector = FVector3(0, 0, 1);
@ -1381,9 +1381,9 @@ DEFINE_MAP_OPTION(lightmode, false)
parse.ParseAssign(); parse.ParseAssign();
parse.sc.MustGetNumber(); parse.sc.MustGetNumber();
if ((parse.sc.Number >= 0 && parse.sc.Number <= 4) || parse.sc.Number == 8) if ((parse.sc.Number >= 0 && parse.sc.Number <= 4) || parse.sc.Number == 8 || parse.sc.Number == 16)
{ {
info->lightmode = uint8_t(parse.sc.Number); info->lightmode = ELightMode(parse.sc.Number);
} }
else else
{ {

View file

@ -388,7 +388,7 @@ void HWViewpointUniforms::SetDefaults()
mNormalViewMatrix.loadIdentity(); mNormalViewMatrix.loadIdentity();
mViewHeight = viewheight; mViewHeight = viewheight;
mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f;
mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8); mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | (static_cast<int>(gl_lightmode) << 16);
mClipLine.X = -10000000.0f; mClipLine.X = -10000000.0f;
mShadowmapFilter = gl_shadowmap_filter; mShadowmapFilter = gl_shadowmap_filter;

View file

@ -127,7 +127,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
} }
else else
{ {
if ((level.lightmode == 2 || (level.lightmode == 8 && cmap->BlendFactor > 0)) && fogcolor == 0) if ((level.lightmode == ELightMode::Doom || (level.isSoftwareLighting() && cmap->BlendFactor > 0)) && fogcolor == 0)
{ {
float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor); float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(light, lightlevel); SetShaderLight(light, lightlevel);
@ -148,7 +148,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
SetFog(fogcolor, fogdensity); SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer. // Korshun: fullbright fog like in software renderer.
if (level.lightmode == 8 && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0) if (level.isSoftwareLighting() && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
{ {
SetSoftLightLevel(255); SetSoftLightLevel(255);
} }

View file

@ -326,7 +326,7 @@ public:
void SetSoftLightLevel(int llevel, int blendfactor = 0) void SetSoftLightLevel(int llevel, int blendfactor = 0)
{ {
if (level.lightmode == 8 && blendfactor == 0) mLightParms[3] = llevel / 255.f; if (level.isSoftwareLighting() && blendfactor == 0) mLightParms[3] = llevel / 255.f;
else mLightParms[3] = -1.f; else mLightParms[3] = -1.f;
} }

View file

@ -164,10 +164,10 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
auto &vp = di->Viewpoint; auto &vp = di->Viewpoint;
// We have no use for Doom lighting special handling here, so disable it for this function. // We have no use for Doom lighting special handling here, so disable it for this function.
int oldlightmode = ::level.lightmode; auto oldlightmode = ::level.lightmode;
if (::level.lightmode == 8) if (::level.isSoftwareLighting())
{ {
::level.lightmode = 2; ::level.SetFallbackLightMode();
state.SetSoftLightLevel(-1); state.SetSoftLightLevel(-1);
} }

View file

@ -106,8 +106,8 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state) void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state)
{ {
int oldlightmode = level.lightmode; auto oldlightmode = level.lightmode;
if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that. if (!hudModelStep && level.isSoftwareLighting()) level.SetFallbackLightMode(); // Software lighting cannot handle 2D content.
for (auto &hudsprite : hudsprites) for (auto &hudsprite : hudsprites)
{ {
if ((!!hudsprite.mframe) == hudModelStep) if ((!!hudsprite.mframe) == hudModelStep)
@ -260,7 +260,7 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po
l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true, 0); l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true, 0);
if (level.lightmode == 8 || l.lightlevel < 92) if (level.isSoftwareLighting() || l.lightlevel < 92)
{ {
// Korshun: the way based on max possible light level for sector like in software renderer. // Korshun: the way based on max possible light level for sector like in software renderer.
double min_L = 36.0 / 31.0 - ((l.lightlevel / 255.0) * (63.0 / 31.0)); // Lightlevel in range 0-63 double min_L = 36.0 / 31.0 - ((l.lightlevel / 255.0) * (63.0 / 31.0)); // Lightlevel in range 0-63
@ -498,8 +498,8 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite. // light mode here to draw the weapon sprite.
int oldlightmode = level.lightmode; auto oldlightmode = level.lightmode;
if (level.lightmode == 8) level.lightmode = 2; if (level.isSoftwareLighting()) level.SetFallbackLightMode();
for (DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext()) for (DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext())
{ {

View file

@ -88,7 +88,7 @@ int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor
if (lightlevel == 0) return 0; if (lightlevel == 0) return 0;
bool darklightmode = (level.lightmode & 2) || (level.lightmode == 8 && blendfactor > 0); bool darklightmode = (level.isDarkLightMode()) || (level.isSoftwareLighting() && blendfactor > 0);
if (darklightmode && lightlevel < 192 && !weapon) if (darklightmode && lightlevel < 192 && !weapon)
{ {
@ -130,7 +130,7 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor)
if (blendfactor == 0) if (blendfactor == 0)
{ {
if (level.lightmode == 8) if (level.isSoftwareLighting())
{ {
return pe; return pe;
} }
@ -174,10 +174,10 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
{ {
float density; float density;
int lightmode = level.lightmode; auto lightmode = level.lightmode;
if (lightmode == 8 && blendfactor > 0) lightmode = 2; // The blendfactor feature does not work with software-style lighting. if (level.isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting.
if (lightmode & 4) if (lightmode == ELightMode::DoomLegacy)
{ {
// uses approximations of Legacy's default settings. // uses approximations of Legacy's default settings.
density = level.fogdensity ? (float)level.fogdensity : 18; density = level.fogdensity ? (float)level.fogdensity : 18;
@ -190,9 +190,9 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
else if ((fogcolor.d & 0xffffff) == 0) else if ((fogcolor.d & 0xffffff) == 0)
{ {
// case 2: black fog // case 2: black fog
if ((lightmode != 8 || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE)) if ((!level.isSoftwareLighting() || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE))
{ {
density = distfogtable[level.lightmode != 0][hw_ClampLight(lightlevel)]; density = distfogtable[level.lightmode != ELightMode::LinearStandard][hw_ClampLight(lightlevel)];
} }
else else
{ {
@ -250,7 +250,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff)) else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff))
{ {
} }
else if (level.fogdensity!=0 || (level.lightmode & 4)) else if (level.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy)
{ {
// case 3: level has fog density set // case 3: level has fog density set
} }
@ -269,7 +269,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
{ {
return false; return false;
} }
else if (level.fogdensity!=0 || (level.lightmode & 4)) else if (level.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy)
{ {
// case 3: level has fog density set // case 3: level has fog density set
return false; return false;

View file

@ -429,7 +429,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
double fadelevel; 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. // 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)) if (vid_rendermode != 4 || level.isDarkLightMode() || level.isSoftwareLighting())
{ {
double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.)); double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.));
fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0); fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0);

View file

@ -2105,6 +2105,7 @@ OptionValue "LightingModes"
3, "$OPTVAL_DARK" 3, "$OPTVAL_DARK"
4, "$OPTVAL_LEGACY" 4, "$OPTVAL_LEGACY"
8, "$OPTVAL_SOFTWARE" 8, "$OPTVAL_SOFTWARE"
16, "$OPTVAL_VANILLA"
} }
OptionValue "Precision" OptionValue "Precision"

View file

@ -119,17 +119,84 @@ vec4 getTexel(vec2 st)
//=========================================================================== //===========================================================================
// //
// Doom lighting equation exactly as calculated by zdoom. // Vanilla Doom wall colormap equation
//
//===========================================================================
float R_WallColormap(float lightnum, float z)
{
// R_ScaleFromGlobalAngle calculation
float projection = 160.0; // projection depends on SCREENBLOCKS!! 160 is the fullscreen value
vec2 line_v1 = pixelpos.xz; // in vanilla this is the first curline vertex
vec2 line_normal = vWorldNormal.xz;
float texscale = projection * clamp(dot(normalize(uCameraPos.xz - line_v1), line_normal), 0.0, 1.0) / z;
float lightz = clamp(16.0 * texscale, 0.0, 47.0);
// scalelight[lightnum][lightz] lookup
float startmap = (15.0 - lightnum) * 4.0;
return startmap - lightz * 0.5;
}
//===========================================================================
//
// Vanilla Doom plane colormap equation
//
//===========================================================================
float R_PlaneColormap(float lightnum, float z)
{
float lightz = clamp(z / 16.0f, 0.0, 127.0);
// zlight[lightnum][lightz] lookup
float startmap = (15.0 - lightnum) * 4.0;
float scale = 160.0 / (lightz + 1.0);
return startmap - scale * 0.5;
}
//===========================================================================
//
// zdoom colormap equation
//
//===========================================================================
float R_ZDoomColormap(float light, float z)
{
float L = light * 255.0;
float vis = min(uGlobVis / z, 24.0 / 32.0);
float shade = 2.0 - (L + 12.0) / 128.0;
float lightscale = shade - vis;
return lightscale * 31.0;
}
float R_DoomColormap(float light, float z)
{
if ((uPalLightLevels >> 16) == 16) // gl_lightmode 16
{
float lightnum = clamp(light * 15.0, 0.0, 15.0);
if (dot(vWorldNormal.xyz, vWorldNormal.xyz) > 0.5)
{
return mix(R_WallColormap(lightnum, z), R_PlaneColormap(lightnum, z), abs(vWorldNormal.y));
}
else // vWorldNormal is not set on sprites
{
return R_PlaneColormap(lightnum, z);
}
}
else
{
return R_ZDoomColormap(light, z);
}
}
//===========================================================================
//
// Doom software lighting equation
// //
//=========================================================================== //===========================================================================
float R_DoomLightingEquation(float light) float R_DoomLightingEquation(float light)
{ {
// L is the integer light level used in the game // z is the depth in view space, positive going into the screen
float L = light * 255.0;
// z is the depth in view/eye space, positive going into the screen
float z; float z;
if ((uPalLightLevels >> 8) == 2) if (((uPalLightLevels >> 8) & 0xff) == 2)
{ {
z = distance(pixelpos.xyz, uCameraPos.xyz); z = distance(pixelpos.xyz, uCameraPos.xyz);
} }
@ -138,17 +205,13 @@ float R_DoomLightingEquation(float light)
z = pixelpos.w; z = pixelpos.w;
} }
// The zdoom light equation float colormap = R_DoomColormap(light, z);
float vis = min(uGlobVis / z, 24.0 / 32.0);
float shade = 2.0 - (L + 12.0) / 128.0;
float lightscale;
if ((uPalLightLevels & 0xff) != 0) if ((uPalLightLevels & 0xff) != 0)
lightscale = float(-floor(-(shade - vis) * 31.0) - 0.5) / 31.0; colormap = floor(colormap) + 0.5;
else
lightscale = shade - vis;
// Result is the normalized colormap index (0 bright .. 1 dark) // Result is the normalized colormap index (0 bright .. 1 dark)
return clamp(lightscale, 1.0 - light, 31.0 / 32.0); return clamp(colormap, 0.0, 31.0) / 32.0;
} }
//=========================================================================== //===========================================================================