我需要在OpenSceneGraph中设置一个指向Source的点,这个点就像太阳一样。我已经知道如何设置灯光,它可以这种方式完成:
//LIGHT CODE ------------------------
osg::ref_ptr<osg::Group> lightGroup (new osg::Group);
osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet());
osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource;
osg::ref_ptr<osg::LightSource> lightSource2 = new osg::LightSource;
// create a local light.
float xCenter = tree->getRoot()->getXCenter();
float yCenter = tree->getRoot()->getYCenter();
osg::Vec4f lightPosition (osg::Vec4f(xCenter, yCenter,75.0,1.0f));
osg::ref_ptr<osg::Light> myLight = new osg::Light;
myLight->setLightNum(1);
myLight->setPosition(lightPosition);
myLight->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f));
myLight->setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f));
myLight->setConstantAttenuation(1.0f);
myLight->setDirection(osg::Vec3(0.0f, 0.0f, -1.0f));
lightSource1->setLight(myLight.get());
lightSource1->setLocalStateSetModes(osg::StateAttribute::ON);
lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON);
//osg::StateSet* lightSS (lightGroup->getOrCreateStateSet());
lightGroup->addChild(lightSource1.get());
//Light markers: small spheres
osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode);
lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(xCenter,yCenter,75),10.0f)));
//Tuto 9: lighting code
root->addChild(lightGroup.get());
//Tuto 9: Adding the light marker geode
root->addChild(lightMarkerGeode.get());
//LIGHTCODE END----------------
这将产生一个如下所示的景观:
上面有光的景观(光由球体表示)
这种光源似乎并没有真正改变景观。 问题是需要什么样的光线设置(即环境,扩散等)才能使太阳模拟光线。
答案 0 :(得分:3)
对于它的价值,OSG论坛/邮件列表通常非常适合回答问题: http://forum.openscenegraph.org/
要尝试在此处回答您的问题 - 这取决于您要点亮的材料的属性。
我发现我加载的某些模型上的材质只会对3种光源类型中的某一种产生反应(具体来说,某些模型只是镜面反射),所以我只需打开所有3种颜色:
osg::Light *light = new osg::Light;
light->setAmbient(osg::Vec4(1.0,1.0,1.0,1.0));
light->setDiffuse(osg::Vec4(1.0,1.0,1.0,1.0));
light->setSpecular(osg::Vec4(1,1,1,1)); // some examples don't have this one
对于您的情况,您也可以重新定义地形的环境和/或漫反射属性。