diff --git a/src/g_level.cpp b/src/g_level.cpp index 5491367ad7..3a29c2098a 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1552,8 +1552,6 @@ void FLevelLocals::Init() brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog; lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces; notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill; - - FLightDefaults::SetAttenuationForLevel(); } //========================================================================== diff --git a/src/g_shared/a_dynlight.h b/src/g_shared/a_dynlight.h index 25d6a34779..77c971942d 100644 --- a/src/g_shared/a_dynlight.h +++ b/src/g_shared/a_dynlight.h @@ -76,7 +76,7 @@ public: void SetSpot(bool spot) { if (spot) m_lightFlags |= LF_SPOT; else m_lightFlags &= ~LF_SPOT; } void SetSpotInnerAngle(double angle) { m_spotInnerAngle = angle; } void SetSpotOuterAngle(double angle) { m_spotOuterAngle = angle; } - static void SetAttenuationForLevel(); + static void SetAttenuationForLevel(bool); void OrderIntensities() { diff --git a/src/gl/renderer/gl_scene.cpp b/src/gl/renderer/gl_scene.cpp index 8e6475c967..c62203be98 100644 --- a/src/gl/renderer/gl_scene.cpp +++ b/src/gl/renderer/gl_scene.cpp @@ -156,6 +156,10 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came if (mainview && toscreen) UpdateShadowMap(); + // Update the attenuation flag of all light defaults for each viewpoint. + // This function will only do something if the setting differs. + FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); + // Render (potentially) multiple views for stereo 3d // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. auto vrmode = VRMode::GetVRMode(mainview && toscreen); diff --git a/src/r_data/a_dynlightdata.cpp b/src/r_data/a_dynlightdata.cpp index f0b66f9720..e6ed0c10b4 100644 --- a/src/r_data/a_dynlightdata.cpp +++ b/src/r_data/a_dynlightdata.cpp @@ -55,6 +55,7 @@ inline PClassActor * GetRealType(PClassActor * ti) } TDeletingArray LightDefaults; +int AttenuationIsSet = -1; //----------------------------------------------------------------------------- // @@ -101,14 +102,18 @@ void FLightDefaults::ApplyProperties(FDynamicLight * light) const light->SetOffset(m_Pos); // this must be the last thing to do. } -void FLightDefaults::SetAttenuationForLevel() +void FLightDefaults::SetAttenuationForLevel(bool yes) { - for (auto ldef : LightDefaults) + if (AttenuationIsSet != int(yes)) { - if (ldef->m_attenuate == -1) + for (auto ldef : LightDefaults) { - if (level.flags3 & LEVEL3_ATTENUATE) ldef->m_lightFlags |= LF_ATTENUATE; else ldef->m_lightFlags &= ~LF_ATTENUATE; + if (ldef->m_attenuate == -1) + { + if (yes) ldef->m_lightFlags |= LF_ATTENUATE; else ldef->m_lightFlags &= ~LF_ATTENUATE; + } } + AttenuationIsSet = yes; } } diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 054e299cde..e853ed6e4e 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -53,6 +53,7 @@ void InitializeActorLights(TArray &LightAssociations); TArray usershaders; extern TDeletingArray LightDefaults; +extern int AttenuationIsSet; //----------------------------------------------------------------------------- @@ -1777,6 +1778,7 @@ void ParseGLDefs() const char *defsLump = NULL; LightDefaults.DeleteAndClear(); + AttenuationIsSet = -1; //gl_DestroyUserShaders(); function says 'todo' switch (gameinfo.gametype) {