Disable specularity for negative lights

esm4-texture
Alexei Kotov 7 months ago
parent debc37d93a
commit e0e4b84e40

@ -41,6 +41,7 @@ namespace SceneUtil
if (mType == LT_Normal) if (mType == LT_Normal)
{ {
light->setDiffuse(mDiffuseColor); light->setDiffuse(mDiffuseColor);
light->setSpecular(mSpecularColor);
traverse(node, nv); traverse(node, nv);
return; return;
} }
@ -65,10 +66,10 @@ namespace SceneUtil
mPhase = mPhase <= 0.5f ? 1.f : 0.25f; 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->setDiffuse(mDiffuseColor * result);
light->setSpecular(result); light->setSpecular(mSpecularColor * result);
traverse(node, nv); traverse(node, nv);
} }
@ -78,4 +79,9 @@ namespace SceneUtil
mDiffuseColor = color; mDiffuseColor = color;
} }
void LightController::setSpecular(const osg::Vec4f& color)
{
mSpecularColor = color;
}
} }

@ -27,12 +27,14 @@ namespace SceneUtil
void setType(LightType type); void setType(LightType type);
void setDiffuse(const osg::Vec4f& color); void setDiffuse(const osg::Vec4f& color);
void setSpecular(const osg::Vec4f& color);
void operator()(SceneUtil::LightSource* node, osg::NodeVisitor* nv); void operator()(SceneUtil::LightSource* node, osg::NodeVisitor* nv);
private: private:
LightType mType; LightType mType;
osg::Vec4f mDiffuseColor; osg::Vec4f mDiffuseColor;
osg::Vec4f mSpecularColor;
float mPhase; float mPhase;
float mBrightness; float mBrightness;
double mStartTime; double mStartTime;

@ -117,19 +117,23 @@ namespace SceneUtil
configureLight(light, radius, isExterior); configureLight(light, radius, isExterior);
osg::Vec4f diffuse = esmLight.mColor; osg::Vec4f diffuse = esmLight.mColor;
osg::Vec4f specular = esmLight.mColor; // ESM format doesn't provide specular
if (esmLight.mNegative) if (esmLight.mNegative)
{ {
diffuse *= -1; diffuse *= -1;
diffuse.a() = 1; diffuse.a() = 1;
// Using specular lighting for negative lights is unreasonable
specular = osg::Vec4f();
} }
light->setDiffuse(diffuse); light->setDiffuse(diffuse);
light->setAmbient(ambient); light->setAmbient(ambient);
light->setSpecular(diffuse); // ESM format doesn't provide specular light->setSpecular(specular);
lightSource->setLight(light); lightSource->setLight(light);
osg::ref_ptr<SceneUtil::LightController> ctrl(new SceneUtil::LightController); osg::ref_ptr<SceneUtil::LightController> ctrl(new SceneUtil::LightController);
ctrl->setDiffuse(light->getDiffuse()); ctrl->setDiffuse(light->getDiffuse());
ctrl->setSpecular(light->getSpecular());
if (esmLight.mFlicker) if (esmLight.mFlicker)
ctrl->setType(SceneUtil::LightController::LT_Flicker); ctrl->setType(SceneUtil::LightController::LT_Flicker);
if (esmLight.mFlickerSlow) if (esmLight.mFlickerSlow)

Loading…
Cancel
Save