]> git.mxchange.org Git - simgear.git/commitdiff
Revert "Remove ambient component of additional lights" because this was Yet Another...
authorFrederic Bouvier <fredfgfs01@free.fr>
Wed, 18 Apr 2012 17:56:31 +0000 (19:56 +0200)
committerFrederic Bouvier <fredfgfs01@free.fr>
Wed, 18 Apr 2012 17:56:31 +0000 (19:56 +0200)
Ambient light is attenuated so it is possible to achieve smooth edges with it

This reverts commit fe8ba57c9412c18681429c4cea6f37a6ef5ec14d.

simgear/scene/model/SGLightAnimation.cxx
simgear/scene/model/animation.hxx

index 33de79fb3294861405d76b71fd134455f429196c..6215efd93060bcb28c1e7aefd7fc754f924d1f6e 100644 (file)
@@ -45,8 +45,9 @@ static EffectMap lightEffectMap;
 
 class SGLightAnimation::UpdateCallback : public osg::NodeCallback {
 public:
-    UpdateCallback(string k, const SGExpressiond* v, SGVec4d d, SGVec4d s) :
+    UpdateCallback(string k, const SGExpressiond* v, SGVec4d a, SGVec4d d, SGVec4d s) :
         _key(k),
+        _ambient(a),
         _diffuse(d),
         _specular(s),
         _animationValue(v)
@@ -63,12 +64,16 @@ public:
             if (iter != lightEffectMap.end()) {
                 simgear::Effect* effect = iter->second;
                 SGPropertyNode* params = effect->parametersProp;
+                params->getNode("ambient")->setValue(_ambient * dim);
                 params->getNode("diffuse")->setValue(_diffuse * dim);
                 params->getNode("specular")->setValue(_specular * dim);
                 BOOST_FOREACH(osg::ref_ptr<simgear::Technique>& technique, effect->techniques)
                 {
                     BOOST_FOREACH(osg::ref_ptr<simgear::Pass>& pass, technique->passes)
                     {
+                        osg::Uniform* amb = pass->getUniform("Ambient");
+                        if (amb)
+                            amb->set(toOsg(_ambient) * dim);
                         osg::Uniform* dif = pass->getUniform("Diffuse");
                         if (dif)
                             dif->set(toOsg(_diffuse) * dim);
@@ -83,6 +88,7 @@ public:
     }
 public:
     string _key;
+    SGVec4d _ambient;
     SGVec4d _diffuse;
     SGVec4d _specular;
     SGSharedPtr<SGExpressiond const> _animationValue;
@@ -102,6 +108,7 @@ SGLightAnimation::SGLightAnimation(const SGPropertyNode* configNode,
     _direction = SGVec3d( getConfig()->getDoubleValue("direction/x"), getConfig()->getDoubleValue("direction/y"), getConfig()->getDoubleValue("direction/z") );
     double l = length(_direction);
     if (l > 0.001) _direction /= l;
+    _ambient = GET_COLOR_VALUE("ambient");
     _diffuse = GET_COLOR_VALUE("diffuse");
     _specular = GET_COLOR_VALUE("specular");
     _attenuation = SGVec3d( getConfig()->getDoubleValue("attenuation/c"), getConfig()->getDoubleValue("attenuation/l"), getConfig()->getDoubleValue("attenuation/q") );
@@ -123,7 +130,7 @@ SGLightAnimation::createAnimationGroup(osg::Group& parent)
     osg::Group* grp = new osg::Group;
     grp->setName("light animation node");
     if (_animationValue.valid())
-        grp->setUpdateCallback(new UpdateCallback(_key, _animationValue, _diffuse, _specular));
+        grp->setUpdateCallback(new UpdateCallback(_key, _animationValue, _ambient, _diffuse, _specular));
     parent.addChild(grp);
     grp->setNodeMask( simgear::MODELLIGHT_BIT );
     return grp;
@@ -149,6 +156,7 @@ SGLightAnimation::install(osg::Node& node)
             SGPropertyNode* params = makeChild(effectProp, "parameters");
             params->getNode("position",true)->setValue(SGVec4d(_position.x(),_position.y(),_position.z(),1.0));
             params->getNode("direction",true)->setValue(SGVec4d(_direction.x(),_direction.y(),_direction.z(),0.0));
+            params->getNode("ambient",true)->setValue(_ambient * dim);
             params->getNode("diffuse",true)->setValue(_diffuse * dim);
             params->getNode("specular",true)->setValue(_specular * dim);
             params->getNode("attenuation",true)->setValue(_attenuation);
@@ -191,6 +199,7 @@ SGLightAnimation::install(osg::Node& node)
 
             SGPropertyNode* params = makeChild(effectProp, "parameters");
             params->getNode("position",true)->setValue(SGVec4d(_position.x(),_position.y(),_position.z(),1.0));
+            params->getNode("ambient",true)->setValue(_ambient * dim);
             params->getNode("diffuse",true)->setValue(_diffuse * dim);
             params->getNode("specular",true)->setValue(_specular * dim);
             params->getNode("attenuation",true)->setValue(_attenuation);
index 4a6b35d09d3c30cb2bec54ea819db054616ac53d..57641d308c1d7dea814c9fa4bb095fd91a510fb8 100644 (file)
@@ -360,6 +360,7 @@ private:
   string _light_type;
   SGVec3d _position;
   SGVec3d _direction;
+  SGVec4d _ambient;
   SGVec4d _diffuse;
   SGVec4d _specular;
   SGVec3d _attenuation;