static const char *microshaderFragSource = { "varying vec4 color;\n" "uniform bool test1=true;\n" "uniform float test2=15.0;\n" "uniform float gauss_num[10];\n" "void main(void)\n" "{\n" " if(test1)\n" " gl_FragColor = clamp( color, 0.0, 1.0 );\n" " else\n" " gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n" "}\n" };
// 数组类型的uniform,数组大小必须与.glsl中的数组大小保持一致 osg::FloatArray* g_GaussNum = new osg::FloatArray(10); osg::Uniform* gauss_num = new osg::Uniform(osg::Uniform::FLOAT, "gauss_num", g_GaussNum->size()); gauss_num->setArray(g_GaussNum);
//如果是vec2类型的数组,使用FLOAT_VEC2,setElement循环设置每一个元素 // 给uniform添加一个回调 osg::Uniform* OffsetUniform = new osg::Uniform("Offset", osg::Vec3(0.0f, 0.0f, 0.0f)); OffsetUniform->setUpdateCallback(new AnimateCallback()); ss->addUniform(OffsetUniform);