|
楼主 |
发表于 2012-11-6 18:39:29
|
显示全部楼层
liuzhiyu123 发表于 2012-11-6 07:44
比较createTexturedQuadGeometry中相应的实现跟您自己的实现,看看缺少哪里,加上就OK了
这个法子我试过了,通过对比,我发现他用的这个createTexturedQuadGeometry()方便用户快速建立一个四边形,然后贴图。。但是源码中除了这段后,并没有对它进行纹理贴图,而是在着色器区域设置的:
1、建立平面
// The water plane
const osg::Vec3& center = scene->getBound().center();
float planeSize = 20.0f * scene->getBound().radius();
osg::Vec3 planeCorner( center.x()-0.5f*planeSize, center.y()-0.5f*planeSize, z );
osg::ref_ptr<osg::Geometry> quad = osg::createTexturedQuadGeometry(
planeCorner, osg::Vec3(planeSize, 0.0f, 0.0f), osg::Vec3(0.0f, planeSize, 0.0f) );
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( quad.get() );
2、设置纹理和着色器uniform
osg::StateSet* ss = geode->getOrCreateStateSet();
ss->setTextureAttributeAndModes( 0, tex2D.get() );
ss->setTextureAttributeAndModes( 1, createTexture("Images/skymap.jpg") );
ss->setTextureAttributeAndModes( 2, createTexture("water_DUDV.jpg") );
ss->setTextureAttributeAndModes( 3, createTexture("water_NM.jpg") );
osg::ref_ptr<osg:rogram> program = new osg::Program;
program->addShader( new osg::Shader(osg::Shader::VERTEX, waterVert) );
program->addShader( new osg::Shader(osg::Shader::FRAGMENT, waterFrag) );
geode->getOrCreateStateSet()->setAttributeAndModes( program.get() );
geode->getOrCreateStateSet()->addUniform( new osg::Uniform("reflection", 0) );
geode->getOrCreateStateSet()->addUniform( new osg::Uniform("defaultTex", 1) );
geode->getOrCreateStateSet()->addUniform( new osg::Uniform("refraction", 2) );
geode->getOrCreateStateSet()->addUniform( new osg::Uniform("normalTex", 3) );
我自定义的绘制四边形方法肯定没有createTexturedQuadGeometry()这样的功效~但我在其中不能添加纹理绑定这部分内容(和源码比较,缺少的部分),因为一旦我绑定四个点纹理后,着色器的水纹和波浪就没效果了。。。况且源码中只是用了这个方法建了四边形,后面没有所谓的setImage等纹理绑定的流程。。。。。。。。。。。求各位高手指点我如何修改?
PS:附上我的代码,一楼为源码
我的代码.zip
(1.25 MB, 下载次数: 30)
|
|