Skip to content

Commit

Permalink
Disable specularity for negative lights
Browse files Browse the repository at this point in the history
  • Loading branch information
Capostrophic committed May 23, 2024
1 parent debc37d commit e0e4b84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions components/sceneutil/lightcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace SceneUtil
if (mType == LT_Normal)
{
light->setDiffuse(mDiffuseColor);
light->setSpecular(mSpecularColor);
traverse(node, nv);
return;
}
Expand All @@ -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);
}
Expand All @@ -78,4 +79,9 @@ namespace SceneUtil
mDiffuseColor = color;
}

void LightController::setSpecular(const osg::Vec4f& color)
{
mSpecularColor = color;
}

}
2 changes: 2 additions & 0 deletions components/sceneutil/lightcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion components/sceneutil/lightutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SceneUtil::LightController> ctrl(new SceneUtil::LightController);
ctrl->setDiffuse(light->getDiffuse());
ctrl->setSpecular(light->getSpecular());
if (esmLight.mFlicker)
ctrl->setType(SceneUtil::LightController::LT_Flicker);
if (esmLight.mFlickerSlow)
Expand Down

0 comments on commit e0e4b84

Please sign in to comment.