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 

gl_vertexID and OpenSceneGraph question

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

Joined: 27 Oct 2016
Posts: 12

PostPosted: Wed Mar 21, 2018 1:52 pm    Post subject:
gl_vertexID and OpenSceneGraph question
Reply with quote

This question is similar to my question in other thread about Texture Buffer Object. I figure this might be a different problem, i.e. on gl_vertexID instead of Texture Buffer Object, that's why I create this thread.

I need to attach additional information to each vertex of a loaded 3D model (in FBX format). In order to make it easier to understand, I will try to make it a very simple case, just say I want to attach additional RGBA color to each vertex (in my actual application, it's more than that).

The additional information is contained in a separate file in JSON format. So, in my application I load the FBX 3D model and the JSON file. The JSON file contains a bunch of RGBA values, with ordering according to the vertices list in the FBX file (as they are output from the same application). Just say first RGBA corresponds to vertex #1, second RGBA corresponds to vertex #2, and so on.

Now the problem is that, in vertex shader we cannot know the current vertex should get which RGBA value. So, I try to use gl_vertexID, as it contains vertex index.

In order to test whether gl_vertexID works or not, I try to test assigning grayscale value to each vertex according to its gl_vertexID :


vec3 FixColor = vec3(float(gl_VertexID)/382.0);
out_vColor1 = vec4(FixColor, 1.0);

Note that I divide it by 382 since the test 3D object is a sphere with 382 vertices. However when I run it, I see that the spiral grayscale color becomes fully white only after only one-quarter of the sphere (Figure A in the attached image). However if I divide it by 2282.0 (which is 382 x 6) :


vec3 FixColor = vec3(float(gl_VertexID)/2282.0);
out_vColor1 = vec4(FixColor, 1.0);

Then we can see the spiral grayscale color nicely becomes fully white in another end (Figure B in the attached image).

In the FBX file, the sphere only uses 382 unique vertices and it uses indexing. That is what I expect when I use gl_vertexID.

However, I find out what the OpenSceneGraph does is actually duplicating the vertices. Most of the vertices are duplicated five times because they are shared by six triangles (Figure C in the attached image).

According to OpenGL reference :

gl_VertexID is a vertex language input variable that holds an integer index for the vertex. The index is implicitly generated by glDrawArrays and other commands that do not reference the content of the GL_ELEMENT_ARRAY_BUFFER, or explicitly generated from the content of the GL_ELEMENT_ARRAY_BUFFER by commands such as glDrawElements. For glDrawElements forms that take a basevertex, gl_VertexID will have this value added to the index from the buffer.

So, it turns out that maybe OpenSceneGraph is using glDrawArrays instead of glDrawElements..that's why the gl_vertexID is the implicitly generated, with automatic increment. So, the vertices are duplicated, and they have different indices, even though they should be identical.

So, my question is that, is there a way for me to force OpenSceneGraph (or maybe the FBX loader plugin) to use indexing as defined in the 3D object file, so that I can use gl_vertexID to attach correct RGBA information to each vertex ?


Thank you!

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 OpenSceneGraph-3.6.4-rc2 tagged robertosfield General 0 Wed Jan 09, 2019 10:33 am View latest post
No new posts Question about .dll only usage. Zachary1234 General 2 Mon Dec 31, 2018 9:05 am View latest post
No new posts Question about 64 bit .dll classloading. Zachary1234 General 0 Sat Dec 29, 2018 10:03 am View latest post
No new posts Question about OSG rasterisation rele... Zachary1234 General 3 Mon Dec 24, 2018 6:06 am View latest post
No new posts Off topic question and request for ideas wernerM General 2 Fri Dec 14, 2018 2:35 pm 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