OpenSceneGraphic 着色器中数组的应用【转】

https://blog.csdn.net/zsq306650083/article/details/50533480

//osg的写法
osg::ref_ptr<osg::StateSet> ss = box->getOrCreateStateSet();
//参考构造函数 Uniform (Type type, const std::string &name, int numElements=1);
osg::ref_ptr<osg::Uniform> unf = new osg::Uniform(osg::Uniform::FLOAT_VEC4,"path",2);
 //给数组赋值
 unf->setElement(0, osg::Vec4f(1, 0, 1, 1));
 unf->setElement(1, osg::Vec4f(1, 0, 1, 1));
 ss->addUniform(unf);

//在片元着色器的写法
uniform vec4 path[2];
void main()
{
    gl_FragColor = path[0];
}

posted on 2019-04-08 17:49  3D入魔  阅读(493)  评论(0编辑  收藏  举报