|
看了array的文章《你所不知的OSG》第二章:OSG与GLSL(1) 。然后按照他给出的例子写了编码,但是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:rogram;
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();
}
另外,我在海军教程中有关着色器的范例中更换别的效果的着色器,例如原来是brick.vert,现在换成rain.vert,结果效果还是没有什么变化,这些着色语言的例子brick.vert,rain.vert也是海军教程提供的data中有的,不知道为什么渲染效果没有改变呢?请教各位。 |
|