|
楼主 |
发表于 2013-1-4 09:51:49
|
显示全部楼层
array 发表于 2013-1-4 09:43
您的光源参数和材质参数设置是否是合理的,还有您是否高估了固定流水线光照的表现力
你帮我看看??
//设置材质
osg::ref_ptr <osg::Material > material=new osg::Material ;
osg::ref_ptr <osg::Texture2D >texture2d=new osg::Texture2D ;
osg::ref_ptr <osg::Image >image;
//光照颜色
material->setAmbient (osg::Material ::FRONT_AND_BACK ,osg::Vec4f (1.0,1.0,1.0,1.0));
//混合光颜色
material->setDiffuse (osg::Material ::FRONT_AND_BACK ,osg::Vec4f (0.5,0.5,0.5,1.0));
//镜面反射光的颜色
material->setSpecular (osg::Material ::FRONT_AND_BACK ,osg::Vec4f (1.0,0.0,0.0,1.0));
//影像点大小
material->setShininess (osg::Material ::FRONT_AND_BACK ,6.0);
//设置纹理
image=osgDB::readImageFile ("Image/whitemetal_diffuse.jpg");
if(image.valid())
{
texture2d->setImage (image.get ());
}
//设置状态
geode->getOrCreateStateSet ()->setAttributeAndModes (material.get (),osg::StateAttribute ::ON );
geode->getOrCreateStateSet ()->setMode (GL_BLEND,osg::StateAttribute ::ON );
geode->getOrCreateStateSet ()->setMode (GL_DEPTH_TEST,osg::StateAttribute ::ON );
geode->getOrCreateStateSet ()->setTextureAttributeAndModes (0,texture2d.get (),osg::StateAttribute ::ON );
//增加光源
osg::ref_ptr <osg:ight > toplight=new osg::Light ;
toplight->setLightNum (0);//给light设置ID
toplight->setPosition (osg::Vec4 (20.0f,20.0f,-20.5f,1.0f));//位置
toplight->setAmbient (osg::Vec4 (1.0f,1.0f,1.0f,1.0f));//全局光
toplight->setDiffuse (osg::Vec4 (1.0f,1.0f,1.0f,1.0f));//混合光,,省略了镜面关
toplight->setConstantAttenuation (0.1f);//
toplight->setLinearAttenuation (0.1f);//光的衰减度
toplight->setQuadraticAttenuation (0.1f);
osg::ref_ptr <osg::LightSource > ls=new osg::LightSource ;
ls->setLight (toplight);
ls->setLocalStateSetModes (osg::StateAttribute ::ON );
osg::ref_ptr <osg::Node >cow=new osg::Node ;
cow=osgDB::readNodeFile ("cow.osg");
root ->addChild (geode.get()) ;
root ->addChild (ls);
root->addChild (cow);
谢谢哈! |
|