[osg-users] Setting vertex attribute array of float

Julien Valentin julienvalentin51 at gmail.com
Mon Mar 27 07:17:34 PDT 2017


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








More information about the osg-users mailing list