- changed light mode handling of the hardware renderer so that it only operates on local copies but doesn't alter the level's setting.

There are several places where a temporary change of light mode is needed, all these made this change in the global level struct. Now the change is only local to the active draw info.
This commit is contained in:
Christoph Oelckers 2019-01-06 09:00:52 +01:00
commit dca4a42dd6
19 changed files with 130 additions and 122 deletions

View file

@ -267,7 +267,17 @@ inline VersionInfo MakeVersion(unsigned int ma, unsigned int mi, unsigned int re
return{ (uint16_t)ma, (uint16_t)mi, (uint32_t)re }; return{ (uint16_t)ma, (uint16_t)mi, (uint32_t)re };
} }
enum class ELightMode : int8_t
{
NotSet = -1,
LinearStandard = 0,
DoomBright = 1,
Doom = 2,
DoomDark = 3,
DoomLegacy = 4,
ZDoomSoftware = 8,
DoomSoftware = 16
};
// Screenshot buffer image data types // Screenshot buffer image data types
enum ESSType enum ESSType

View file

@ -128,7 +128,7 @@ CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL)
else if (newself > 4) newself = 8; else if (newself > 4) newself = 8;
else if (newself < 0) newself = 0; else if (newself < 0) newself = 0;
if (self != newself) self = newself; if (self != newself) self = newself;
else if ((level.info == nullptr || level.info->lightmode == ELightMode::NotSet)) level.lightmode = (ELightMode)*self; else if ((level.info == nullptr || level.info->lightmode == ELightMode::NotSet)) level.lightMode = (ELightMode)*self;
} }
@ -1530,7 +1530,7 @@ void G_InitLevelLocals ()
level.DefaultEnvironment = info->DefaultEnvironment; level.DefaultEnvironment = info->DefaultEnvironment;
level.lightmode = info->lightmode == ELightMode::NotSet? (ELightMode)*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

@ -296,18 +296,6 @@ 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
{ {

View file

@ -198,7 +198,7 @@ struct FLevelLocals : public FLevelData
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
ELightMode lightmode; ELightMode lightMode;
bool brightfog; bool brightfog;
bool lightadditivesurfaces; bool lightadditivesurfaces;
bool notexturefill; bool notexturefill;
@ -231,21 +231,6 @@ struct FLevelLocals : public FLevelData
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;
}
}; };
#ifndef NO_DEFINE_LEVEL #ifndef NO_DEFINE_LEVEL

View file

@ -361,7 +361,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i
FRenderViewpoint savevp; FRenderViewpoint savevp;
sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetNoSoftLightLevel();
CopyToBackbuffer(&bounds, false); CopyToBackbuffer(&bounds, false);
// strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers

View file

@ -75,7 +75,7 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
else state.AlphaFunc(Alpha_Greater, 0.f); else state.AlphaFunc(Alpha_Greater, 0.f);
state.SetColor(lightlevel, rellight, di->isFullbrightScene(), Colormap, alpha); di->SetColor(state, lightlevel, rellight, di->isFullbrightScene(), Colormap, alpha);
// for additively drawn decals we must temporarily set the fog color to black. // for additively drawn decals we must temporarily set the fog color to black.
PalEntry fc = state.GetFogColor(); PalEntry fc = state.GetFogColor();
if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One) if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One)
@ -106,9 +106,9 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
FColormap thiscm; FColormap thiscm;
thiscm.FadeColor = Colormap.FadeColor; thiscm.FadeColor = Colormap.FadeColor;
thiscm.CopyFrom3DLight(&lightlist[k]); thiscm.CopyFrom3DLight(&lightlist[k]);
state.SetColor(thisll, rellight, di->isFullbrightScene(), thiscm, alpha); di->SetColor(state, thisll, rellight, di->isFullbrightScene(), thiscm, alpha);
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize(); if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize();
state.SetFog(thisll, rellight, di->isFullbrightScene(), &thiscm, false); di->SetFog(state, thisll, rellight, di->isFullbrightScene(), &thiscm, false);
state.SetSplitPlanes(lightlist[k].plane, lowplane); state.SetSplitPlanes(lightlist[k].plane, lowplane);
state.Draw(DT_TriangleFan, vertindex, 4); state.Draw(DT_TriangleFan, vertindex, 4);
@ -147,7 +147,7 @@ void HWDrawInfo::DrawDecals(FRenderState &state, TArray<GLDecal *> &decals)
else else
{ {
state.EnableSplit(false); state.EnableSplit(false);
state.SetFog(gldecal->lightlevel, gldecal->rellight, isFullbrightScene(), &gldecal->Colormap, false); SetFog(state, gldecal->lightlevel, gldecal->rellight, isFullbrightScene(), &gldecal->Colormap, false);
} }
} }
gldecal->DrawDecal(this, state); gldecal->DrawDecal(this, state);
@ -169,7 +169,7 @@ void GLWall::DrawDecalsForMirror(HWDrawInfo *di, FRenderState &state, TArray<GLD
state.SetDepthMask(false); state.SetDepthMask(false);
state.SetDepthBias(-1, -128); state.SetDepthBias(-1, -128);
state.SetLightIndex(-1); state.SetLightIndex(-1);
state.SetFog(lightlevel, rellight + getExtraLight(), di->isFullbrightScene(), &Colormap, false); di->SetFog(state, lightlevel, rellight + getExtraLight(), di->isFullbrightScene(), &Colormap, false);
for (auto gldecal : decals) for (auto gldecal : decals)
{ {
if (gldecal->decal->Side == seg->sidedef) if (gldecal->decal->Side == seg->sidedef)

View file

@ -125,6 +125,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
mClipper = &staticClipper; mClipper = &staticClipper;
Viewpoint = parentvp; Viewpoint = parentvp;
lightmode = level.lightMode;
if (uniforms) if (uniforms)
{ {
VPUniforms = *uniforms; VPUniforms = *uniforms;
@ -605,7 +606,7 @@ void HWDrawInfo::DrawEndScene2D(sector_t * viewsector, FRenderState &state)
DrawPlayerSprites(false, state); DrawPlayerSprites(false, state);
state.SetSoftLightLevel(-1); state.SetNoSoftLightLevel();
// Restore standard rendering state // Restore standard rendering state
state.SetRenderStyle(STYLE_Translucent); state.SetRenderStyle(STYLE_Translucent);

View file

@ -140,6 +140,7 @@ struct HWDrawInfo
HWDrawList drawlists[GLDL_TYPES]; HWDrawList drawlists[GLDL_TYPES];
int vpIndex; int vpIndex;
ELightMode lightmode;
HWDrawInfo * outer = nullptr; HWDrawInfo * outer = nullptr;
int FullbrightFlags; int FullbrightFlags;
@ -210,6 +211,14 @@ private:
int SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane); int SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane);
int CreateOtherPlaneVertices(subsector_t *sub, const secplane_t *plane); int CreateOtherPlaneVertices(subsector_t *sub, const secplane_t *plane);
void DrawPSprite(HUDSprite *huds, FRenderState &state); void DrawPSprite(HUDSprite *huds, FRenderState &state);
void SetColor(FRenderState &state, int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false);
void SetFog(FRenderState &state, int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);
void SetShaderLight(FRenderState &state, float level, float olight);
int CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor);
PalEntry CalcLightColor(int light, PalEntry pe, int blendfactor);
float GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor);
bool CheckFog(sector_t *frontsector, sector_t *backsector);
WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int cm, area_t in_area, const DVector3 &playerpos);
public: public:
void SetCameraPos(const DVector3 &pos) void SetCameraPos(const DVector3 &pos)
@ -307,5 +316,21 @@ public:
GLDecal *AddDecal(bool onmirror); GLDecal *AddDecal(bool onmirror);
bool isSoftwareLighting() const
{
return lightmode >= ELightMode::ZDoomSoftware;
}
bool isDarkLightMode() const
{
return !!((int)lightmode & (int)ELightMode::Doom);
}
void SetFallbackLightMode()
{
lightmode = ELightMode::Doom;
}
}; };

View file

@ -304,8 +304,8 @@ void GLFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent)
state.SetNormal(plane.plane.Normal().X, plane.plane.Normal().Z, plane.plane.Normal().Y); state.SetNormal(plane.plane.Normal().X, plane.plane.Normal().Z, plane.plane.Normal().Y);
state.SetColor(lightlevel, rel, di->isFullbrightScene(), Colormap, alpha); di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, alpha);
state.SetFog(lightlevel, rel, di->isFullbrightScene(), &Colormap, false); di->SetFog(state, lightlevel, rel, di->isFullbrightScene(), &Colormap, false);
state.SetObjectColor(FlatColor | 0xff000000); state.SetObjectColor(FlatColor | 0xff000000);
state.SetAddColor(AddColor | 0xff000000); state.SetAddColor(AddColor | 0xff000000);

View file

@ -964,14 +964,14 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
if (gltexture && gltexture->tex->isFullbright()) if (gltexture && gltexture->tex->isFullbright())
{ {
// glowing textures are always drawn full bright without color // glowing textures are always drawn full bright without color
state.SetColor(255, 0, false, origin->colormap, 1.f); di->SetColor(state, 255, 0, false, origin->colormap, 1.f);
state.SetFog(255, 0, false, &origin->colormap, false); di->SetFog(state, 255, 0, false, &origin->colormap, false);
} }
else else
{ {
int rel = getExtraLight(); int rel = getExtraLight();
state.SetColor(origin->lightlevel, rel, di->isFullbrightScene(), origin->colormap, 1.0f); di->SetColor(state, origin->lightlevel, rel, di->isFullbrightScene(), origin->colormap, 1.0f);
state.SetFog(origin->lightlevel, rel, di->isFullbrightScene(), &origin->colormap, false); di->SetFog(state, origin->lightlevel, rel, di->isFullbrightScene(), &origin->colormap, false);
} }

View file

@ -37,19 +37,21 @@
// set current light color // set current light color
// //
//========================================================================== //==========================================================================
void FRenderState::SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon) void HWDrawInfo::SetColor(FRenderState &state, int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon)
{ {
if (fullbright) if (fullbright)
{ {
SetColorAlpha(0xffffff, alpha, 0); state.SetColorAlpha(0xffffff, alpha, 0);
SetSoftLightLevel(255); if (isSoftwareLighting()) state.SetSoftLightLevel(255);
else state.SetNoSoftLightLevel();
} }
else else
{ {
int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor); int hwlightlevel = CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor);
PalEntry pe = hw_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor); PalEntry pe = CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor);
SetColorAlpha(pe, alpha, cm.Desaturation); state.SetColorAlpha(pe, alpha, cm.Desaturation);
SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor); if (isSoftwareLighting()) state.SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor);
else state.SetNoSoftLightLevel();
} }
} }
@ -59,7 +61,7 @@ void FRenderState::SetColor(int sectorlightlevel, int rellight, bool fullbright,
// //
//========================================================================== //==========================================================================
void FRenderState::SetShaderLight(float level, float olight) void HWDrawInfo::SetShaderLight(FRenderState &state, float level, float olight)
{ {
const float MAXDIST = 256.f; const float MAXDIST = 256.f;
const float THRESHOLD = 96.f; const float THRESHOLD = 96.f;
@ -78,11 +80,11 @@ void FRenderState::SetShaderLight(float level, float olight)
lightfactor = 1.f + ((olight / level) - 1.f) * FACTOR; lightfactor = 1.f + ((olight / level) - 1.f) * FACTOR;
if (lightfactor == 1.f) lightdist = 0.f; // save some code in the shader if (lightfactor == 1.f) lightdist = 0.f; // save some code in the shader
SetLightParms(lightfactor, lightdist); state.SetLightParms(lightfactor, lightdist);
} }
else else
{ {
SetLightParms(1.f, 0.f); state.SetLightParms(1.f, 0.f);
} }
} }
@ -93,7 +95,7 @@ void FRenderState::SetShaderLight(float level, float olight)
// //
//========================================================================== //==========================================================================
void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive) void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive)
{ {
PalEntry fogcolor; PalEntry fogcolor;
float fogdensity; float fogdensity;
@ -106,7 +108,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
else if (cmap != NULL && !fullbright) else if (cmap != NULL && !fullbright)
{ {
fogcolor = cmap->FadeColor; fogcolor = cmap->FadeColor;
fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor); fogdensity = GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor);
fogcolor.a = 0; fogcolor.a = 0;
} }
else else
@ -122,19 +124,19 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
// no fog in enhanced vision modes! // no fog in enhanced vision modes!
if (fogdensity == 0 || gl_fogmode == 0) if (fogdensity == 0 || gl_fogmode == 0)
{ {
EnableFog(false); state.EnableFog(false);
SetFog(0, 0); state.SetFog(0, 0);
} }
else else
{ {
if ((level.lightmode == ELightMode::Doom || (level.isSoftwareLighting() && cmap->BlendFactor > 0)) && fogcolor == 0) if ((lightmode == ELightMode::Doom || (isSoftwareLighting() && cmap->BlendFactor > 0)) && fogcolor == 0)
{ {
float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor); float light = (float)CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(light, lightlevel); SetShaderLight(state, light, lightlevel);
} }
else else
{ {
SetLightParms(1.f, 0.f); state.SetLightParms(1.f, 0.f);
} }
// For additive rendering using the regular fog color here would mean applying it twice // For additive rendering using the regular fog color here would mean applying it twice
@ -144,13 +146,13 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
fogcolor = 0; fogcolor = 0;
} }
EnableFog(true); state.EnableFog(true);
SetFog(fogcolor, fogdensity); state.SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer. // Korshun: fullbright fog like in software renderer.
if (level.isSoftwareLighting() && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0) if (isSoftwareLighting() && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
{ {
SetSoftLightLevel(255); state.SetSoftLightLevel(255);
} }
} }
} }

View file

@ -163,7 +163,6 @@ protected:
int mVertexOffsets[2]; // one per binding point int mVertexOffsets[2]; // one per binding point
IIndexBuffer *mIndexBuffer; IIndexBuffer *mIndexBuffer;
void SetShaderLight(float level, float olight);
public: public:
VSMatrix mModelMatrix; VSMatrix mModelMatrix;
@ -328,10 +327,15 @@ public:
void SetSoftLightLevel(int llevel, int blendfactor = 0) void SetSoftLightLevel(int llevel, int blendfactor = 0)
{ {
if (level.isSoftwareLighting() && blendfactor == 0) mLightParms[3] = llevel / 255.f; if (blendfactor == 0) mLightParms[3] = llevel / 255.f;
else mLightParms[3] = -1.f; else mLightParms[3] = -1.f;
} }
void SetNoSoftLightLevel()
{
mLightParms[3] = -1.f;
}
void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom) void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom)
{ {
auto &tn = top.Normal(); auto &tn = top.Normal();
@ -498,9 +502,6 @@ public:
return mInterpolationFactor; return mInterpolationFactor;
} }
void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false);
void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);
// API-dependent render interface // API-dependent render interface
// Draw commands // Draw commands

View file

@ -164,11 +164,11 @@ 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.
auto oldlightmode = ::level.lightmode; auto oldlightmode = di->lightmode;
if (::level.isSoftwareLighting()) if (di->isSoftwareLighting())
{ {
::level.SetFallbackLightMode(); di->SetFallbackLightMode();
state.SetSoftLightLevel(-1); state.SetNoSoftLightLevel();
} }
@ -215,7 +215,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
state.SetObjectColor(0xffffffff); state.SetObjectColor(0xffffffff);
} }
} }
::level.lightmode = oldlightmode; di->lightmode = oldlightmode;
state.SetDepthClamp(oldClamp); state.SetDepthClamp(oldClamp);
} }

View file

@ -116,7 +116,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
if (!Colormap.FadeColor.isBlack()) if (!Colormap.FadeColor.isBlack())
{ {
float dist = Dist2(vp.Pos.X, vp.Pos.Y, x, y); float dist = Dist2(vp.Pos.X, vp.Pos.Y, x, y);
int fogd = hw_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.FogDensity, Colormap.BlendFactor); int fogd = di->GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.FogDensity, Colormap.BlendFactor);
// this value was determined by trial and error and is scale dependent! // this value was determined by trial and error and is scale dependent!
float factor = 0.05f + exp(-fogd * dist / 62500.f); float factor = 0.05f + exp(-fogd * dist / 62500.f);
@ -161,7 +161,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
state.SetObjectColor(finalcol); state.SetObjectColor(finalcol);
state.SetAddColor(cursec->AdditiveColors[sector_t::sprites] | 0xff000000); state.SetAddColor(cursec->AdditiveColors[sector_t::sprites] | 0xff000000);
} }
state.SetColor(lightlevel, rel, di->isFullbrightScene(), Colormap, trans); di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, trans);
} }
@ -188,7 +188,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
else RenderStyle.BlendOp = STYLEOP_Fuzz; // subtractive with models is not going to work. else RenderStyle.BlendOp = STYLEOP_Fuzz; // subtractive with models is not going to work.
} }
if (!foglayer) state.SetFog(foglevel, rel, di->isFullbrightScene(), &Colormap, additivefog); if (!foglayer) di->SetFog(state, foglevel, rel, di->isFullbrightScene(), &Colormap, additivefog);
else else
{ {
state.EnableFog(false); state.EnableFog(false);
@ -229,10 +229,10 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
thiscm.Decolorize(); thiscm.Decolorize();
} }
state.SetColor(thisll, rel, di->isFullbrightScene(), thiscm, trans); di->SetColor(state, thisll, rel, di->isFullbrightScene(), thiscm, trans);
if (!foglayer) if (!foglayer)
{ {
state.SetFog(thislight, rel, di->isFullbrightScene(), &thiscm, additivefog); di->SetFog(state, thislight, rel, di->isFullbrightScene(), &thiscm, additivefog);
} }
state.SetSplitPlanes(*topplane, *lowplane); state.SetSplitPlanes(*topplane, *lowplane);
} }
@ -260,7 +260,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
if (foglayer) if (foglayer)
{ {
// If we get here we know that we have colored fog and no fixed colormap. // If we get here we know that we have colored fog and no fixed colormap.
state.SetFog(foglevel, rel, false, &Colormap, additivefog); di->SetFog(state, foglevel, rel, false, &Colormap, additivefog);
state.SetTextureMode(TM_FOGLAYER); state.SetTextureMode(TM_FOGLAYER);
state.SetRenderStyle(STYLE_Translucent); state.SetRenderStyle(STYLE_Translucent);
state.Draw(DT_TriangleStrip, vertexindex, 4); state.Draw(DT_TriangleStrip, vertexindex, 4);

View file

@ -69,7 +69,7 @@ void GLWall::RenderFogBoundary(HWDrawInfo *di, FRenderState &state)
{ {
int rel = rellight + getExtraLight(); int rel = rellight + getExtraLight();
state.EnableDrawBufferAttachments(false); state.EnableDrawBufferAttachments(false);
state.SetFog(lightlevel, rel, false, &Colormap, false); di->SetFog(state, lightlevel, rel, false, &Colormap, false);
state.SetEffect(EFF_FOGBOUNDARY); state.SetEffect(EFF_FOGBOUNDARY);
state.AlphaFunc(Alpha_GEqual, 0.f); state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetDepthBias(-1, -128); state.SetDepthBias(-1, -128);
@ -97,8 +97,8 @@ void GLWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state)
// Use sphere mapping for this // Use sphere mapping for this
state.SetEffect(EFF_SPHEREMAP); state.SetEffect(EFF_SPHEREMAP);
state.SetColor(lightlevel, 0, di->isFullbrightScene(), Colormap, 0.1f); di->SetColor(state, lightlevel, 0, di->isFullbrightScene(), Colormap, 0.1f);
state.SetFog(lightlevel, 0, di->isFullbrightScene(), &Colormap, true); di->SetFog(state, lightlevel, 0, di->isFullbrightScene(), &Colormap, true);
state.SetRenderStyle(STYLE_Add); state.SetRenderStyle(STYLE_Add);
state.AlphaFunc(Alpha_Greater, 0); state.AlphaFunc(Alpha_Greater, 0);
@ -163,7 +163,7 @@ void GLWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
{ {
if (tmode == TM_NORMAL) state.SetTextureMode(TM_CLAMPY); if (tmode == TM_NORMAL) state.SetTextureMode(TM_CLAMPY);
} }
state.SetFog(255, 0, di->isFullbrightScene(), nullptr, false); di->SetFog(state, 255, 0, di->isFullbrightScene(), nullptr, false);
} }
if (type != RENDERWALL_COLOR && seg->sidedef != nullptr) if (type != RENDERWALL_COLOR && seg->sidedef != nullptr)
{ {
@ -205,8 +205,8 @@ void GLWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
float absalpha = fabsf(alpha); float absalpha = fabsf(alpha);
if (lightlist == nullptr) if (lightlist == nullptr)
{ {
if (type != RENDERWALL_M2SNF) state.SetFog(lightlevel, rel, di->isFullbrightScene(), &Colormap, RenderStyle == STYLE_Add); if (type != RENDERWALL_M2SNF) di->SetFog(state, lightlevel, rel, di->isFullbrightScene(), &Colormap, RenderStyle == STYLE_Add);
state.SetColor(lightlevel, rel, di->isFullbrightScene(), Colormap, absalpha); di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, absalpha);
RenderWall(di, state, rflags); RenderWall(di, state, rflags);
} }
else else
@ -227,8 +227,8 @@ void GLWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
thiscm.FadeColor = Colormap.FadeColor; thiscm.FadeColor = Colormap.FadeColor;
thiscm.FogDensity = Colormap.FogDensity; thiscm.FogDensity = Colormap.FogDensity;
thiscm.CopyFrom3DLight(&(*lightlist)[i]); thiscm.CopyFrom3DLight(&(*lightlist)[i]);
state.SetColor(thisll, rel, false, thiscm, absalpha); di->SetColor(state, thisll, rel, false, thiscm, absalpha);
if (type != RENDERWALL_M2SNF) state.SetFog(thisll, rel, false, &thiscm, RenderStyle == STYLE_Add); if (type != RENDERWALL_M2SNF) di->SetFog(state, thisll, rel, false, &thiscm, RenderStyle == STYLE_Add);
state.SetSplitPlanes((*lightlist)[i].plane, lowplane); state.SetSplitPlanes((*lightlist)[i].plane, lowplane);
RenderWall(di, state, rflags); RenderWall(di, state, rflags);
} }
@ -263,8 +263,8 @@ void GLWall::RenderTranslucentWall(HWDrawInfo *di, FRenderState &state)
else else
{ {
state.AlphaFunc(Alpha_GEqual, 0.f); state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetColor(lightlevel, 0, false, Colormap, fabsf(alpha)); di->SetColor(state, lightlevel, 0, false, Colormap, fabsf(alpha));
state.SetFog(lightlevel, 0, false, &Colormap, RenderStyle == STYLE_Add); di->SetFog(state, lightlevel, 0, false, &Colormap, RenderStyle == STYLE_Add);
state.EnableTexture(false); state.EnableTexture(false);
RenderWall(di, state, GLWall::RWF_NOSPLIT); RenderWall(di, state, GLWall::RWF_NOSPLIT);
state.EnableTexture(true); state.EnableTexture(true);
@ -2058,7 +2058,7 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_
bool isportal = seg->linedef->isVisualPortal() && seg->sidedef == seg->linedef->sidedef[0]; bool isportal = seg->linedef->isVisualPortal() && seg->sidedef == seg->linedef->sidedef[0];
sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector; sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector;
bool drawfogboundary = !di->isFullbrightScene() && hw_CheckFog(frontsector, backsec); bool drawfogboundary = !di->isFullbrightScene() && di->CheckFog(frontsector, backsec);
FTexture *tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true); FTexture *tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true);
if (tex != NULL) if (tex != NULL)
{ {

View file

@ -66,7 +66,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
} }
else else
{ {
state.SetColor(huds->lightlevel, 0, isFullbrightScene(), huds->cm, huds->alpha, true); SetColor(state, huds->lightlevel, 0, isFullbrightScene(), huds->cm, huds->alpha, true);
} }
state.SetLightIndex(-1); state.SetLightIndex(-1);
state.SetRenderStyle(huds->RenderStyle); state.SetRenderStyle(huds->RenderStyle);
@ -115,14 +115,14 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state) void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state)
{ {
auto oldlightmode = level.lightmode; auto oldlightmode = lightmode;
if (!hudModelStep && level.isSoftwareLighting()) level.SetFallbackLightMode(); // Software lighting cannot handle 2D content. if (!hudModelStep && isSoftwareLighting()) SetFallbackLightMode(); // Software lighting cannot handle 2D content.
for (auto &hudsprite : hudsprites) for (auto &hudsprite : hudsprites)
{ {
if ((!!hudsprite.mframe) == hudModelStep) if ((!!hudsprite.mframe) == hudModelStep)
DrawPSprite(&hudsprite, state); DrawPSprite(&hudsprite, state);
} }
level.lightmode = oldlightmode; lightmode = oldlightmode;
} }
@ -219,7 +219,7 @@ static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp, double ticFrac)
// //
//========================================================================== //==========================================================================
static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int cm, area_t in_area, const DVector3 &playerpos) WeaponLighting HWDrawInfo::GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int cm, area_t in_area, const DVector3 &playerpos)
{ {
WeaponLighting l; WeaponLighting l;
@ -267,9 +267,9 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) l.cm.ClearColor(); if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) l.cm.ClearColor();
} }
l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true, 0); l.lightlevel = CalcLightLevel(l.lightlevel, getExtraLight(), true, 0);
if (level.isSoftwareLighting() || l.lightlevel < 92) if (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
@ -507,8 +507,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.
auto oldlightmode = level.lightmode; auto oldlightmode = lightmode;
if (level.isSoftwareLighting()) level.SetFallbackLightMode(); if (isSoftwareLighting()) 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())
{ {
@ -555,7 +555,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
} }
hudsprites.Push(hudsprite); hudsprites.Push(hudsprite);
} }
level.lightmode = oldlightmode; lightmode = oldlightmode;
PrepareTargeterSprites(); PrepareTargeterSprites();
} }

View file

@ -29,6 +29,7 @@
#include "r_sky.h" #include "r_sky.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "hw_lighting.h" #include "hw_lighting.h"
#include "hwrenderer/scene/hw_drawinfo.h"
// externally settable lighting properties // externally settable lighting properties
static float distfogtable[2][256]; // light to fog conversion table for black fog static float distfogtable[2][256]; // light to fog conversion table for black fog
@ -82,13 +83,13 @@ CUSTOM_CVAR(Int,gl_fogmode,1,CVAR_ARCHIVE|CVAR_NOINITCALL)
// //
//========================================================================== //==========================================================================
int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor) int HWDrawInfo::CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor)
{ {
int light; int light;
if (lightlevel == 0) return 0; if (lightlevel == 0) return 0;
bool darklightmode = (level.isDarkLightMode()) || (level.isSoftwareLighting() && blendfactor > 0); bool darklightmode = (isDarkLightMode()) || (isSoftwareLighting() && blendfactor > 0);
if (darklightmode && lightlevel < 192 && !weapon) if (darklightmode && lightlevel < 192 && !weapon)
{ {
@ -124,13 +125,13 @@ int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor
// //
//========================================================================== //==========================================================================
PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor) PalEntry HWDrawInfo::CalcLightColor(int light, PalEntry pe, int blendfactor)
{ {
int r,g,b; int r,g,b;
if (blendfactor == 0) if (blendfactor == 0)
{ {
if (level.isSoftwareLighting()) if (isSoftwareLighting())
{ {
return pe; return pe;
} }
@ -170,12 +171,12 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor)
// //
//========================================================================== //==========================================================================
float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor) float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor)
{ {
float density; float density;
auto lightmode = level.lightmode; auto oldlightmode = lightmode;
if (level.isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting. if (isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting.
if (lightmode == ELightMode::DoomLegacy) if (lightmode == ELightMode::DoomLegacy)
{ {
@ -190,9 +191,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 ((!level.isSoftwareLighting() || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE)) if ((!isSoftwareLighting() || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE))
{ {
density = distfogtable[level.lightmode != ELightMode::LinearStandard][hw_ClampLight(lightlevel)]; density = distfogtable[lightmode != ELightMode::LinearStandard][hw_ClampLight(lightlevel)];
} }
else else
{ {
@ -232,7 +233,7 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
// //
//========================================================================== //==========================================================================
bool hw_CheckFog(sector_t *frontsector, sector_t *backsector) bool HWDrawInfo::CheckFog(sector_t *frontsector, sector_t *backsector)
{ {
if (frontsector == backsector) return false; // there can't be a boundary if both sides are in the same sector. if (frontsector == backsector) return false; // there can't be a boundary if both sides are in the same sector.
@ -250,7 +251,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 == ELightMode::DoomLegacy) else if (level.fogdensity!=0 || lightmode == ELightMode::DoomLegacy)
{ {
// case 3: level has fog density set // case 3: level has fog density set
} }
@ -269,7 +270,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
{ {
return false; return false;
} }
else if (level.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy) else if (level.fogdensity!=0 || lightmode == ELightMode::DoomLegacy)
{ {
// case 3: level has fog density set // case 3: level has fog density set
return false; return false;

View file

@ -7,11 +7,6 @@
struct Colormap; struct Colormap;
int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor);
PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor);
float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor);
bool hw_CheckFog(sector_t *frontsector, sector_t *backsector);
inline int hw_ClampLight(int lightlevel) inline int hw_ClampLight(int lightlevel)
{ {
return clamp(lightlevel, 0, 255); return clamp(lightlevel, 0, 255);

View file

@ -428,14 +428,14 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
// is necessary in order to best reproduce Doom's original lighting. // is necessary in order to best reproduce Doom's original lighting.
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. if (vid_rendermode != 4 || level.lightMode == ELightMode::Doom || level.lightMode == ELightMode::ZDoomSoftware || level.lightMode == ELightMode::DoomSoftware)
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);
} }
else else
{ {
// 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.
fadelevel = 1. - clamp(lightlevel, 0, 255) / 255.f; fadelevel = 1. - clamp(lightlevel, 0, 255) / 255.f;
} }