OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Setting vertex attribute array of float


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Bruno Oliveira
Guest





PostPosted: Mon Mar 20, 2017 9:55 am    Post subject:
Setting vertex attribute array of float
Reply with quote

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
Back to top
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 337

PostPosted: Mon Mar 27, 2017 2:17 pm    Post subject:
Re: Setting vertex attribute array of float
Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Post Processing Effect - Vertex Shade... guyv General 27 Sat Sep 16, 2017 3:48 am View latest post
No new posts Pro Process Effect Vertex Shader not ... guyv General 1 Fri Sep 15, 2017 10:22 pm View latest post
No new posts Post Process Effect Vertex Shader guyv General 1 Fri Sep 15, 2017 8:29 pm View latest post
No new posts Setting up a shadowDepthCamera wernerM General 0 Fri Sep 08, 2017 11:28 am View latest post
No new posts using modern shaders with osg - setti... antiro42 General 18 Fri Sep 01, 2017 9:30 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP