diff --git a/src/common/rendering/hwrenderer/data/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h index 4ada8a452..236cc9e45 100644 --- a/src/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -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 diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index a2f444ccf..698fa432e 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -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); } diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index d1c1c353d..a3e88f64a 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -39,6 +39,7 @@ struct HWHorizonInfo int lightlevel; FColormap colormap; PalEntry specialcolor; + bool sunlight; }; struct FPortalSceneState; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 4b1c6b296..dc08b1b83 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -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()) {