[osg-users] Setting vertex attribute array of float

106 views
Skip to first unread message

Bruno Oliveira

unread,
Mar 20, 2017, 5:52:10 AM3/20/17
to OpenSceneGraph Users
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?



Julien Valentin

unread,
Mar 27, 2017, 10:14:37 AM3/27/17
to osg-...@lists.openscenegraph.org
Hi
I think you are mixing old and new glsl syntax.
varying is old syntax
attribute is new syntax
you should harmonize your shader (use #version GLSLSVERSION at the begin of your shader) all will become incremental with compiler errors
PS:
Code:
use the code tag to create expandable code section


Cheers

Bruno Oliveira wrote:
> 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?
>

> ------------------
> Post generated by Mail2Forum


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70563#70563

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply all
Reply to author
Forward
0 new messages