Hi, i'm finding a lot of difficult to solve this issue: pass uniform and attribute parameters from osg application to shader.
In particular, referred to attribute (or in) parameter in vertex program : Code: #version 150 attribute vec3 Vertex; attribute vec2 Uv; uniform mat4 osg_ProjectionMatrix; uniform mat4 ViewMatrix; uniform mat4 osg_ViewMatrixInverse; uniform vec3 ModelScale; How can i pass these data from my osg application? Currently, in my osg applycation i use : Code: mProgram->addBindAttribLocation("Vertex",0); mProgram->addBindAttribLocation("Uv",8); Is it correct? I looked at an example on "OpenSceneGraph 3 cookbook" chapter 6, "Using the bump tecnique" where to pass these attributes : Code: attribute vec3 tangent; attribute vec3 binormal; The authors (Rui Wang, Xuelei Qian) use a ComputeTangentVisitor nodevisitor class to compute tangent and binormal for each vertex: Code: class ComputeTangentVisitor : public osg::NodeVisitor { public: void apply( osg::Node& node ) { traverse(node); } void apply( osg::Geode& node ) { for ( unsigned int i=0; i<node.getNumDrawables(); ++i ) { osg::Geometry* geom = dynamic_cast<osg::Geometry*>( node.getDrawable(i) ); if ( geom ) generateTangentArray( geom ); //setGeometryVertexArray(geom); } traverse( node ); } void generateTangentArray( osg::Geometry* geom ) { osg::ref_ptr<osgUtil::TangentSpaceGenerator> tsg = new osgUtil::TangentSpaceGenerator; tsg->generate( geom ); geom->setVertexAttribArray( 6, tsg->getTangentArray() ); geom->setVertexAttribBinding( 6, osg::Geometry::BIND_PER_VERTEX ); geom->setVertexAttribArray( 7, tsg->getBinormalArray() ); geom->setVertexAttribBinding( 7, osg::Geometry::BIND_PER_VERTEX ); } }; and bind them with the following code : Code: ComputeTangentVisitor ctv; ctv.setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ); mModel->accept( ctv ); mProgram->addBindAttribLocation("tangent",6); mProgram->addBindAttribLocation("binormal",7); But, in my case vertex are already exist. So i suppose to use only : mProgram->addBindAttribLocation("Vertex",0); And what about the Uv parameter? The texture i have to pass to fragment, is a RTT Camera image, on which i would like to apply some effects. How can i pass these texture coordinates to shader? About the uniform parameters, is there a way to pass the ViewMatrix? I used myCamera->getViewMatrix() in my osgapplication, and i set uniform to this value inside a callback: Code: osg::ref_ptr<osg::Uniform> viewUniformParam = new osg::Uniform("ViewMatrix", osg::Matrixf()); viewUniformParam->setUpdateCallback( new ViewMatrixCallback(mApplicationCamera.get()) ); with : Code: class ViewMatrixCallback : public osg::Uniform::Callback { public: ViewMatrixCallback(osg::Camera* appcamera): osg::Uniform::Callback() { mApplicationCamera=appcamera; }; virtual void operator()( osg::Uniform* uniform, osg::NodeVisitor* nv ) { osg::Matrix vmFromCamera=mApplicationCamera->getViewMatrix(); uniform->set( vmFromCamera ); } protected: osg::ref_ptr<osg::Camera> mApplicationCamera; }; But i get no results. Could you give me some suggestions? Thank you! Cheers, Andrea ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52925#52925 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org