From e0e4b84e40cd7fd969e6f80f67193ad31b8670b0 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Fri, 24 May 2024 00:22:52 +0300 Subject: [PATCH] Disable specularity for negative lights --- components/sceneutil/lightcontroller.cpp | 12 +++++++++--- components/sceneutil/lightcontroller.hpp | 2 ++ components/sceneutil/lightutil.cpp | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/sceneutil/lightcontroller.cpp b/components/sceneutil/lightcontroller.cpp index caff6826f5..18b4580571 100644 --- a/components/sceneutil/lightcontroller.cpp +++ b/components/sceneutil/lightcontroller.cpp @@ -41,6 +41,7 @@ namespace SceneUtil if (mType == LT_Normal) { light->setDiffuse(mDiffuseColor); + light->setSpecular(mSpecularColor); traverse(node, nv); return; } @@ -65,10 +66,10 @@ namespace SceneUtil mPhase = mPhase <= 0.5f ? 1.f : 0.25f; } - osg::Vec4f result = mDiffuseColor * mBrightness * node->getActorFade(); + const float result = mBrightness * node->getActorFade(); - light->setDiffuse(result); - light->setSpecular(result); + light->setDiffuse(mDiffuseColor * result); + light->setSpecular(mSpecularColor * result); traverse(node, nv); } @@ -78,4 +79,9 @@ namespace SceneUtil mDiffuseColor = color; } + void LightController::setSpecular(const osg::Vec4f& color) + { + mSpecularColor = color; + } + } diff --git a/components/sceneutil/lightcontroller.hpp b/components/sceneutil/lightcontroller.hpp index 13f5501bf9..0c088d579f 100644 --- a/components/sceneutil/lightcontroller.hpp +++ b/components/sceneutil/lightcontroller.hpp @@ -27,12 +27,14 @@ namespace SceneUtil void setType(LightType type); void setDiffuse(const osg::Vec4f& color); + void setSpecular(const osg::Vec4f& color); void operator()(SceneUtil::LightSource* node, osg::NodeVisitor* nv); private: LightType mType; osg::Vec4f mDiffuseColor; + osg::Vec4f mSpecularColor; float mPhase; float mBrightness; double mStartTime; diff --git a/components/sceneutil/lightutil.cpp b/components/sceneutil/lightutil.cpp index f69461fa3c..8a38ee9b72 100644 --- a/components/sceneutil/lightutil.cpp +++ b/components/sceneutil/lightutil.cpp @@ -117,19 +117,23 @@ namespace SceneUtil configureLight(light, radius, isExterior); osg::Vec4f diffuse = esmLight.mColor; + osg::Vec4f specular = esmLight.mColor; // ESM format doesn't provide specular if (esmLight.mNegative) { diffuse *= -1; diffuse.a() = 1; + // Using specular lighting for negative lights is unreasonable + specular = osg::Vec4f(); } light->setDiffuse(diffuse); light->setAmbient(ambient); - light->setSpecular(diffuse); // ESM format doesn't provide specular + light->setSpecular(specular); lightSource->setLight(light); osg::ref_ptr ctrl(new SceneUtil::LightController); ctrl->setDiffuse(light->getDiffuse()); + ctrl->setSpecular(light->getSpecular()); if (esmLight.mFlicker) ctrl->setType(SceneUtil::LightController::LT_Flicker); if (esmLight.mFlickerSlow)