[osg-users] Setting vertex attribute array of float

Bruno Oliveira bruno.manata.oliveira at gmail.com
Mon Mar 20 02:52:06 PDT 2017


Hello,

I have a point cloud and I need to pass some float attribute. I need one
flag per vertex, so I am using vertex attribute array.

Here's how I do it:




*osg::Geometry* geom = (...);osg::ref_ptr<osg::FloatArray> vvv(new
osg::FloatArray());*


*for (int i = 0; i < nPoints; i++) vvv->push_back(0.);*

*geom->setVertexAttribArray(20, vvv);geom->setVertexAttribBinding(20,
osg::Geometry::BIND_PER_VERTEX);*


Then I create a osg::Program and bind the attribute as follows:


*m_program->addBindAttribLocation("classif", 20); *


And here's my vertex shader that paints the vertices as *white* if the
attribute "classif" is > 0.1 and *red* otherwise:
















*            // Vertex Shader            "varying   vec4 vcolor;\n"
    "attribute float classif;\n"            "\n"            "void
main()\n"            "{\n"            "  vcolor      = ((classif > 0.1) ?
vec4(1., 1., 1., 1.) : vec4(1., 0., 0. ,1.));\n"            "  gl_Position
= ftransform();\n"            "}\n",            // Fragment Shader
    "varying vec4 vcolor;\n"            "void main() {\n"            "
gl_FragColor = vcolor;\n"            "}"*



Now, what happens is that, despite I set all attributes to 0., all the
points appear as white (i.e. the shader is interpreting the attribute as >
0.1). And no matter what values I put on the attributes, the vertices are
always rendered as white.

Any hints on why this is happening?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170320/5040d490/attachment-0001.htm>


More information about the osg-users mailing list