|
对模型进行纹理贴图时,纹理的颜色是“灰度还是多波段”在纹理渲染设置时有什么区别吗?我利用osgstereoimage的代码生成立体像对,这个成功了,两张照片都是灰度的。但是当我拿多波段的影像测试时,osgstereoimage中有一个函数叫做:createColorToGreyscaleStateSet(),它的实现如下:
osg::StateSet* createColorToGreyscaleStateSet()
{
osg::StateSet* stateset = new osg::StateSet;
osg:rogram* program = new osg::Program;
stateset->setAttribute(program);
const char* fragSource =
{
"uniform sampler2D baseTexture;\n"
"uniform mat4 colorMatrix;\n"
"void main(void)\n"
"{\n"
" vec4 color = texture2D( baseTexture, gl_TexCoord[0].st );\n"
" gl_FragColor = colorMatrix * color;\n"
"}\n"
};
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragSource));
stateset->addUniform(new osg::Uniform("baseTexture",0));
osg::Matrixf colorMatrix(
0.3f, 0.3f, 0.3f, 0.0f,
0.59f, 0.59f, 0.59f, 0.0f,
0.11f, 0.11f, 0.11f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
stateset->addUniform(new osg::Uniform("colorMatrix",colorMatrix));
return stateset;
}
用处是将渲染改成灰度的状态,在设置viewer的时候调用此接口。我发现如果不调用此接口,那么影像不论是灰度的,还是多波段的都无法显示出来。如果调用此接口,多波段的影像则显示为灰度图。下图分别是调用和未调用
“rootNode_overlap->setStateSet(createColorToGreyscaleStateSet());”的情况。
我怀疑是否在加载纹理时设置的渲染和纹理属性不对?我的设置如下:
osg::Texture2D* texture = new osg::Texture2D;
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D:INEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
texture->setResizeNonPowerOfTwoHint(false);
texture->setImage(image);
// set up the drawstate.
osg::StateSet* dstate = new osg::StateSet;
dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
dstate->setMode(GL_LIGHTING,osg::StateAttribute::ON);
dstate->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
dstate->setTextureAttribute(0, texmat);
osg::Vec4Array* colors = new osg::Vec4Array();
colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,0.0f));
osg:rawArrays* elements = new osg::DrawArrays(osg::PrimitiveSet:UADS,0,coords->size());
geom->setVertexArray(coords);
geom->setTexCoordArray(0,tcoords);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->addPrimitiveSet(elements);
// set up the geode.
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);
请各位帮忙看一下,比较急,在线等,谢谢。 |
-
调用createColorToGreyscaleStateSet()
-
未调用
|