Correctly apply sunlight to line portals

This commit is contained in:
Magnus Norddahl 2025-05-13 15:18:33 +02:00
commit 156d7e7af2
4 changed files with 12 additions and 15 deletions

View file

@ -491,11 +491,6 @@ public:
mSurfaceUniforms.uAddColor = toFVector4(pe);
}
void SetAddColor(FVector4 color)
{
mSurfaceUniforms.uAddColor = color;
}
void SetNpotEmulation(float factor, float offset)
{
#ifdef NPOT_EMULATION

View file

@ -1042,11 +1042,6 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
}
di->SetCameraPos(vp.Pos);
if (level.lightmaps && texture->GetID() == skyflatnum)
{
state.SetAddColor(FVector4(level.SunColor * level.SunIntensity, 0.0f));
}
if (texture->isFullbright())
{
// glowing textures are always drawn full bright without color
@ -1060,6 +1055,12 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
SetFog(state, di->Level, di->lightmode, origin->lightlevel, rel, di->isFullbrightScene(), &origin->colormap, false, di->drawctx->portalState.inskybox);
}
if (origin->sunlight)
{
float attenuation = std::max(FVector3(sp->plane.normal) | level.SunDirection, 0.0f);
FVector3 suncolor = level.SunColor * (attenuation * level.SunIntensity);
state.SetDynLight(suncolor.X, suncolor.Y, suncolor.Z);
}
state.EnableBrightmap(true);
state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, NO_TRANSLATION, -1);
@ -1067,11 +1068,6 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetRenderStyle(STYLE_Source);
if (level.lightmaps && texture->GetID() == skyflatnum)
{
state.SetAddColor(FVector4(0.0f, 0.0f, 0.0f, 0.0f));
}
bool texmatrix = SetPlaneTextureRotation(state, sp, texture);
for (unsigned i = 0; i < vcount; i += 4)
@ -1082,6 +1078,9 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
if (texmatrix)
state.SetTextureMatrix(VSMatrix::identity());
if (origin->sunlight)
state.SetDynLight(0.0f, 0.0f, 0.0f);
}

View file

@ -39,6 +39,7 @@ struct HWHorizonInfo
int lightlevel;
FColormap colormap;
PalEntry specialcolor;
bool sunlight;
};
struct FPortalSceneState;

View file

@ -842,6 +842,7 @@ bool HWWall::DoHorizon(HWWallDispatcher *di, FRenderState& state, seg_t * seg,se
hi.lightlevel = hw_ClampLight(fs->GetCeilingLight());
hi.colormap = fs->Colormap;
hi.specialcolor = fs->SpecialColors[sector_t::ceiling];
hi.sunlight = level.lightmaps && fs->GetTexture(sector_t::floor) == skyflatnum && level.SunDirection.Z < 0.0f;
if (fs->e->XFloor.ffloors.Size())
{
@ -871,6 +872,7 @@ bool HWWall::DoHorizon(HWWallDispatcher *di, FRenderState& state, seg_t * seg,se
hi.lightlevel = hw_ClampLight(fs->GetFloorLight());
hi.colormap = fs->Colormap;
hi.specialcolor = fs->SpecialColors[sector_t::floor];
hi.sunlight = level.lightmaps && fs->GetTexture(sector_t::ceiling) == skyflatnum && level.SunDirection.Z > 0.0f;
if (fs->e->XFloor.ffloors.Size())
{