For using generic vertex attributes, you could refer to these (partial) code snippets. I pass some custom texture coordinates as a float2 attribute with each vertex. Can be easily changed to float4, if needed.
osg::Geometry *meshGeom; // so we use a float attribute array instead osg::Vec2Array* xypositions = new osg::Vec2Array(); xypositions->setName("xypos"); // for loop over all vertices, adds texture coordinates for (...) xypositions->push_back(osg::Vec2(xcoord, ycoord)); // only use binding to attribute index 6 or 7 as these are not used by OSG. meshGeom->setVertexAttribArray(6, xypositions); meshGeom->setVertexAttribNormalize(6, false); meshGeom->setVertexAttribBinding(6, osg::Geometry::BIND_PER_VERTEX); osg::Program* program = new osg::Program; program->setName( "mesh" ); program->addBindAttribLocation("xypos", 6); // and here is how I access the custom attribute in a vertex shader. // I perform a gaussian interpolation over sample values contained in a 2D texture, // and use that to displace a 3D mesh vertically. static const char *VertexShader = { "#version 120\n" "uniform float K;\n" "uniform float N;\n" "uniform sampler2D datatex;\n" "in vec2 xypos;\n" "void main(void)\n" "{\n" " // gaussian 3x3 filter kernel;\n" " float foo = 41.0 * texture2D(datatex, xypos).x\n" " + 26.0 * texture2D(datatex, xypos+vec2(+K , 0 )).x\n" " + 26.0 * texture2D(datatex, xypos+vec2(-K , 0 )).x\n" " + 26.0 * texture2D(datatex, xypos+vec2( 0 ,+N )).x\n" " + 26.0 * texture2D(datatex, xypos+vec2( 0 ,-N )).x\n" " + 16.0 * texture2D(datatex, xypos+vec2(-K ,+N )).x\n" " + 16.0 * texture2D(datatex, xypos+vec2(-K ,-N )).x\n" " + 16.0 * texture2D(datatex, xypos+vec2(+K ,+N )).x\n" " + 16.0 * texture2D(datatex, xypos+vec2(+K ,-N )).x;\n" _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org