diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 9fcc86a32e..5c81626d9b 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -1156,6 +1156,8 @@ namespace SceneUtil { for (const auto& bound : it->second) { + if (bound.mLightSource->getEmpty()) + continue; const auto* light = bound.mLightSource->getLight(frameNum); if (light->getDiffuse().x() >= 0.f) mPPLightBuffer->setLight(frameNum, light, bound.mLightSource->getRadius()); diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index 915f95c829..b4d4755056 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -118,6 +118,8 @@ namespace SceneUtil unsigned int mLastAppliedFrame; + bool mEmpty = false; + public: META_Node(SceneUtil, LightSource) @@ -147,6 +149,16 @@ namespace SceneUtil return mActorFade; } + void setEmpty(bool empty) + { + mEmpty = empty; + } + + bool getEmpty() const + { + return mEmpty; + } + /// Get the osg::Light safe for modification in the given frame. /// @par May be used externally to animate the light's color/attenuation properties, /// and is used internally to synchronize the light's position with the position of the LightSource. diff --git a/components/sceneutil/lightutil.cpp b/components/sceneutil/lightutil.cpp index 031899848d..adf36ff04f 100644 --- a/components/sceneutil/lightutil.cpp +++ b/components/sceneutil/lightutil.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include @@ -11,6 +13,33 @@ #include "util.hpp" #include "visitor.hpp" +namespace +{ + class CheckEmptyLightVisitor : public osg::NodeVisitor + { + public: + CheckEmptyLightVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) {} + + void apply(osg::Drawable& drawable) override + { + if (!mEmpty) + return; + + if (dynamic_cast(&drawable)) + mEmpty = false; + else + traverse(drawable); + } + + void apply(osg::Geometry& geometry) override + { + mEmpty = false; + } + + bool mEmpty = true; + }; +} + namespace SceneUtil { @@ -64,6 +93,12 @@ namespace SceneUtil osg::Group* attachTo = visitor.mFoundNode ? visitor.mFoundNode : node; osg::ref_ptr lightSource = createLightSource(esmLight, lightMask, isExterior, osg::Vec4f(0,0,0,1)); attachTo->addChild(lightSource); + + CheckEmptyLightVisitor emptyVisitor; + node->accept(emptyVisitor); + + lightSource->setEmpty(emptyVisitor.mEmpty); + return lightSource; }