- 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
parent 3328821a98
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 };
}
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
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 < 0) newself = 0;
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.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.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces;
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
{

View file

@ -198,7 +198,7 @@ struct FLevelLocals : public FLevelData
float MusicVolume;
// Hardware render stuff that can either be set via CVAR or MAPINFO
ELightMode lightmode;
ELightMode lightMode;
bool brightfog;
bool lightadditivesurfaces;
bool notexturefill;
@ -231,21 +231,6 @@ struct FLevelLocals : public FLevelData
return savegamerestore
|| (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

View file

@ -361,7 +361,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i
FRenderViewpoint savevp;
sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false);
glDisable(GL_STENCIL_TEST);
gl_RenderState.SetSoftLightLevel(-1);
gl_RenderState.SetNoSoftLightLevel();
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

View file

@ -75,7 +75,7 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
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.
PalEntry fc = state.GetFogColor();
if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One)
@ -106,9 +106,9 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
FColormap thiscm;
thiscm.FadeColor = Colormap.FadeColor;
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();
state.SetFog(thisll, rellight, di->isFullbrightScene(), &thiscm, false);
di->SetFog(state, thisll, rellight, di->isFullbrightScene(), &thiscm, false);
state.SetSplitPlanes(lightlist[k].plane, lowplane);
state.Draw(DT_TriangleFan, vertindex, 4);
@ -147,7 +147,7 @@ void HWDrawInfo::DrawDecals(FRenderState &state, TArray<GLDecal *> &decals)
else
{
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);
@ -169,7 +169,7 @@ void GLWall::DrawDecalsForMirror(HWDrawInfo *di, FRenderState &state, TArray<GLD
state.SetDepthMask(false);
state.SetDepthBias(-1, -128);
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)
{
if (gldecal->decal->Side == seg->sidedef)

View file

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

View file

@ -140,6 +140,7 @@ struct HWDrawInfo
HWDrawList drawlists[GLDL_TYPES];
int vpIndex;
ELightMode lightmode;
HWDrawInfo * outer = nullptr;
int FullbrightFlags;
@ -210,6 +211,14 @@ private:
int SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane);
int CreateOtherPlaneVertices(subsector_t *sub, const secplane_t *plane);
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:
void SetCameraPos(const DVector3 &pos)
@ -307,5 +316,21 @@ public:
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.SetColor(lightlevel, rel, di->isFullbrightScene(), Colormap, alpha);
state.SetFog(lightlevel, rel, di->isFullbrightScene(), &Colormap, false);
di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, alpha);
di->SetFog(state, lightlevel, rel, di->isFullbrightScene(), &Colormap, false);
state.SetObjectColor(FlatColor | 0xff000000);
state.SetAddColor(AddColor | 0xff000000);

View file

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

View file

@ -37,19 +37,21 @@
// 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)
{
SetColorAlpha(0xffffff, alpha, 0);
SetSoftLightLevel(255);
state.SetColorAlpha(0xffffff, alpha, 0);
if (isSoftwareLighting()) state.SetSoftLightLevel(255);
else state.SetNoSoftLightLevel();
}
else
{
int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor);
PalEntry pe = hw_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor);
SetColorAlpha(pe, alpha, cm.Desaturation);
SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor);
int hwlightlevel = CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor);
PalEntry pe = CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor);
state.SetColorAlpha(pe, alpha, cm.Desaturation);
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 THRESHOLD = 96.f;
@ -78,11 +80,11 @@ void FRenderState::SetShaderLight(float level, float olight)
lightfactor = 1.f + ((olight / level) - 1.f) * FACTOR;
if (lightfactor == 1.f) lightdist = 0.f; // save some code in the shader
SetLightParms(lightfactor, lightdist);
state.SetLightParms(lightfactor, lightdist);
}
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;
float fogdensity;
@ -106,7 +108,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
else if (cmap != NULL && !fullbright)
{
fogcolor = cmap->FadeColor;
fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor);
fogdensity = GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor);
fogcolor.a = 0;
}
else
@ -122,19 +124,19 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
// no fog in enhanced vision modes!
if (fogdensity == 0 || gl_fogmode == 0)
{
EnableFog(false);
SetFog(0, 0);
state.EnableFog(false);
state.SetFog(0, 0);
}
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);
SetShaderLight(light, lightlevel);
float light = (float)CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(state, light, lightlevel);
}
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
@ -144,13 +146,13 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
fogcolor = 0;
}
EnableFog(true);
SetFog(fogcolor, fogdensity);
state.EnableFog(true);
state.SetFog(fogcolor, fogdensity);
// 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
IIndexBuffer *mIndexBuffer;
void SetShaderLight(float level, float olight);
public:
VSMatrix mModelMatrix;
@ -328,10 +327,15 @@ public:
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;
}
void SetNoSoftLightLevel()
{
mLightParms[3] = -1.f;
}
void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom)
{
auto &tn = top.Normal();
@ -498,9 +502,6 @@ public:
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
// Draw commands

View file

@ -164,11 +164,11 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
auto &vp = di->Viewpoint;
// We have no use for Doom lighting special handling here, so disable it for this function.
auto oldlightmode = ::level.lightmode;
if (::level.isSoftwareLighting())
auto oldlightmode = di->lightmode;
if (di->isSoftwareLighting())
{
::level.SetFallbackLightMode();
state.SetSoftLightLevel(-1);
di->SetFallbackLightMode();
state.SetNoSoftLightLevel();
}
@ -215,7 +215,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
state.SetObjectColor(0xffffffff);
}
}
::level.lightmode = oldlightmode;
di->lightmode = oldlightmode;
state.SetDepthClamp(oldClamp);
}

View file

@ -116,7 +116,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
if (!Colormap.FadeColor.isBlack())
{
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!
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.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.
}
if (!foglayer) state.SetFog(foglevel, rel, di->isFullbrightScene(), &Colormap, additivefog);
if (!foglayer) di->SetFog(state, foglevel, rel, di->isFullbrightScene(), &Colormap, additivefog);
else
{
state.EnableFog(false);
@ -229,10 +229,10 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
thiscm.Decolorize();
}
state.SetColor(thisll, rel, di->isFullbrightScene(), thiscm, trans);
di->SetColor(state, thisll, rel, di->isFullbrightScene(), thiscm, trans);
if (!foglayer)
{
state.SetFog(thislight, rel, di->isFullbrightScene(), &thiscm, additivefog);
di->SetFog(state, thislight, rel, di->isFullbrightScene(), &thiscm, additivefog);
}
state.SetSplitPlanes(*topplane, *lowplane);
}
@ -260,7 +260,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
if (foglayer)
{
// 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.SetRenderStyle(STYLE_Translucent);
state.Draw(DT_TriangleStrip, vertexindex, 4);

View file

@ -69,7 +69,7 @@ void GLWall::RenderFogBoundary(HWDrawInfo *di, FRenderState &state)
{
int rel = rellight + getExtraLight();
state.EnableDrawBufferAttachments(false);
state.SetFog(lightlevel, rel, false, &Colormap, false);
di->SetFog(state, lightlevel, rel, false, &Colormap, false);
state.SetEffect(EFF_FOGBOUNDARY);
state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetDepthBias(-1, -128);
@ -97,8 +97,8 @@ void GLWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state)
// Use sphere mapping for this
state.SetEffect(EFF_SPHEREMAP);
state.SetColor(lightlevel, 0, di->isFullbrightScene(), Colormap, 0.1f);
state.SetFog(lightlevel, 0, di->isFullbrightScene(), &Colormap, true);
di->SetColor(state, lightlevel, 0, di->isFullbrightScene(), Colormap, 0.1f);
di->SetFog(state, lightlevel, 0, di->isFullbrightScene(), &Colormap, true);
state.SetRenderStyle(STYLE_Add);
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);
}
state.SetFog(255, 0, di->isFullbrightScene(), nullptr, false);
di->SetFog(state, 255, 0, di->isFullbrightScene(), nullptr, false);
}
if (type != RENDERWALL_COLOR && seg->sidedef != nullptr)
{
@ -205,8 +205,8 @@ void GLWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
float absalpha = fabsf(alpha);
if (lightlist == nullptr)
{
if (type != RENDERWALL_M2SNF) state.SetFog(lightlevel, rel, di->isFullbrightScene(), &Colormap, RenderStyle == STYLE_Add);
state.SetColor(lightlevel, rel, di->isFullbrightScene(), Colormap, absalpha);
if (type != RENDERWALL_M2SNF) di->SetFog(state, lightlevel, rel, di->isFullbrightScene(), &Colormap, RenderStyle == STYLE_Add);
di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, absalpha);
RenderWall(di, state, rflags);
}
else
@ -227,8 +227,8 @@ void GLWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
thiscm.FadeColor = Colormap.FadeColor;
thiscm.FogDensity = Colormap.FogDensity;
thiscm.CopyFrom3DLight(&(*lightlist)[i]);
state.SetColor(thisll, rel, false, thiscm, absalpha);
if (type != RENDERWALL_M2SNF) state.SetFog(thisll, rel, false, &thiscm, RenderStyle == STYLE_Add);
di->SetColor(state, thisll, rel, false, thiscm, absalpha);
if (type != RENDERWALL_M2SNF) di->SetFog(state, thisll, rel, false, &thiscm, RenderStyle == STYLE_Add);
state.SetSplitPlanes((*lightlist)[i].plane, lowplane);
RenderWall(di, state, rflags);
}
@ -263,8 +263,8 @@ void GLWall::RenderTranslucentWall(HWDrawInfo *di, FRenderState &state)
else
{
state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetColor(lightlevel, 0, false, Colormap, fabsf(alpha));
state.SetFog(lightlevel, 0, false, &Colormap, RenderStyle == STYLE_Add);
di->SetColor(state, lightlevel, 0, false, Colormap, fabsf(alpha));
di->SetFog(state, lightlevel, 0, false, &Colormap, RenderStyle == STYLE_Add);
state.EnableTexture(false);
RenderWall(di, state, GLWall::RWF_NOSPLIT);
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];
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);
if (tex != NULL)
{

View file

@ -66,7 +66,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
}
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.SetRenderStyle(huds->RenderStyle);
@ -115,14 +115,14 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state)
{
auto oldlightmode = level.lightmode;
if (!hudModelStep && level.isSoftwareLighting()) level.SetFallbackLightMode(); // Software lighting cannot handle 2D content.
auto oldlightmode = lightmode;
if (!hudModelStep && isSoftwareLighting()) SetFallbackLightMode(); // Software lighting cannot handle 2D content.
for (auto &hudsprite : hudsprites)
{
if ((!!hudsprite.mframe) == hudModelStep)
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;
@ -267,9 +267,9 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po
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.
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
// light mode here to draw the weapon sprite.
auto oldlightmode = level.lightmode;
if (level.isSoftwareLighting()) level.SetFallbackLightMode();
auto oldlightmode = lightmode;
if (isSoftwareLighting()) SetFallbackLightMode();
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);
}
level.lightmode = oldlightmode;
lightmode = oldlightmode;
PrepareTargeterSprites();
}

View file

@ -29,6 +29,7 @@
#include "r_sky.h"
#include "g_levellocals.h"
#include "hw_lighting.h"
#include "hwrenderer/scene/hw_drawinfo.h"
// externally settable lighting properties
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;
if (lightlevel == 0) return 0;
bool darklightmode = (level.isDarkLightMode()) || (level.isSoftwareLighting() && blendfactor > 0);
bool darklightmode = (isDarkLightMode()) || (isSoftwareLighting() && blendfactor > 0);
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;
if (blendfactor == 0)
{
if (level.isSoftwareLighting())
if (isSoftwareLighting())
{
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;
auto lightmode = level.lightmode;
if (level.isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting.
auto oldlightmode = lightmode;
if (isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting.
if (lightmode == ELightMode::DoomLegacy)
{
@ -190,9 +191,9 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
else if ((fogcolor.d & 0xffffff) == 0)
{
// 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
{
@ -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.
@ -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.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy)
else if (level.fogdensity!=0 || lightmode == ELightMode::DoomLegacy)
{
// case 3: level has fog density set
}
@ -269,7 +270,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
{
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
return false;

View file

@ -7,11 +7,6 @@
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)
{
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.
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.isDarkLightMode() || level.isSoftwareLighting())
if (vid_rendermode != 4 || level.lightMode == ELightMode::Doom || level.lightMode == ELightMode::ZDoomSoftware || level.lightMode == ELightMode::DoomSoftware)
{
double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.));
fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0);
}
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;
}