|
发表于 2009-11-13 19:49:37
|
显示全部楼层
您好,看了您的文章。然后按照您给出的例子写了编码,但是cow.osg显示出来的仍然是原来那个样子亮闪闪的牛,不是像array那样的“卡通着色器效果”。源代码如下,请看看有什么问题:
头文件省略
static const char* vertSource = {
"varying vec3 normal;\n"
"void main()\n"
"{\n"
" normal = normalize(gl_NormalMatrix * gl_Normal);\n"
" gl_Position = ftransform();\n"
"}\n"
}
static const char* fragSource = {
"varying vec3 normal;\n"
"void main()\n"
"{\n"
" float intensity = dot(vec3(gl_LightSource[0].position), normal);\n"
" if (intensity > 0.95) gl_FragColor = vec4(1.0,0.5,0.5,1.0);\n"
" else if (intensity > 0.5) gl_FragColor = vec4(0.6,0.3,0.3,1.0);\n"
" else if (intensity > 0.25) gl_FragColor = vec4(0.4,0.2,0.2,1.0);\n"
" else gl_FragColor = vec4(0.2,0.1,0.1,1.0);\n"
"}\n"
}
void loadShaders( osg::StateSet* ss )
{
osg::ref_ptr<osg::Shader> vertShader =
new osg::Shader( osg::Shader::VERTEX, vertSource );
osg::ref_ptr<osg::Shader> fragShader =
new osg::Shader( osg::Shader::FRAGMENT, fragSource );
osg::ref_ptr<osg:rogram> program = new osg::Program;
program->addShader( vertShader.get() );
program->addShader( fragShader.get() );
if ( ss )
ss->setAttributeAndModes( program.get(), osg::StateAttribute::ON );
}
int main( int argc, char** argv )
{
osg::ref_ptr<osg::Node> root = osgDB::readNodeFile( "cow.osg" );
loadShaders( root->getOrCreateStateSet() );
osgViewer::Viewer viewer;
viewer.setSceneData( root.get() );
return viewer.run();
} |
|