|
楼主 |
发表于 2010-5-6 17:13:53
|
显示全部楼层
下面是我创建天空盒的代码:
osg::Node* CSkyBox::createSkyBox()
{
osg::StateSet* stateset = new osg::StateSet();
//设置纹理为替代模式
osg::TexEnv* te = new osg::TexEnv;
te->setMode(osg::TexEnv::REPLACE);
stateset->setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);
//立方体纹理
osg::TexGen *tg = new osg::TexGen;
tg->setMode(osg::TexGen::NORMAL_MAP);
stateset->setTextureAttributeAndModes(0, tg, osg::StateAttribute::ON);
//设置纹理矩阵
osg::TexMat *tm = new osg::TexMat;
stateset->setTextureAttribute(0, tm);
//读纹理图片
osg::TextureCubeMap* skymap = readCubeMap();
if (skymap)
{
stateset->setDataVariance(osg::Object:YNAMIC);
osg::ref_ptr<osg:rogram> skyProgram = new osg::Program;
osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX,skybox_vert);
skyProgram->addShader(vertex_shader);
osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT,skybox_frag);
skyProgram->addShader(fragment_shader);
stateset->addUniform(new osg::Uniform("sun_vec", osg::Vec3d(0.0,0.0,1.0)));
stateset->addUniform(new osg::Uniform("sun_shininess", 240.f));
stateset->addUniform(new osg::Uniform("sun_strength", 6.0f));
stateset->addUniform(new osg::Uniform("sky",0));
stateset->setAttributeAndModes(skyProgram);
stateset->setTextureAttribute(0,skymap);
}
//stateset->setTextureAttributeAndModes(0, skymap, osg::StateAttribute::ON);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
// clear the depth to the far plane.
osg::Depth* depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
depth->setRange(1.0,1.0);
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );
//设置绘制顺序,天空盒子优先
stateset->setRenderBinDetails(-1,"RenderBin");
osg::Drawable* drawable = new osg::ShapeDrawable(new osg::Sphere(m_centre,m_r));
drawable->setName("skyboxGeom");
osg::Geode* geode = new osg::Geode;
geode->setCullingActive(false);
geode->setStateSet( stateset );
geode->addDrawable(drawable);
osg::Transform* transform = new MoveEarthySkyWithEyePointTransform;
transform->setCullingActive(false);
transform->addChild(geode);
osg::ClearNode* clearNode = new osg::ClearNode;
clearNode->setCullCallback(new TexMatCallback(*tm));//更新纹理矩阵
clearNode->addChild(transform);
return clearNode;
}
请帮忙看看是否有错误。谢谢。
我把这个天空盒节点导出为osg文件,在ShapeDrawable节点下有color 1 1 1 1 的代码,请问这个color可以去掉吗?怎么去掉。
麻烦了。 |
|