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
EonStrife
Newbie


Joined: 27 Oct 2016
Posts: 12

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

Hi,
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 :

Code:

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) :

Code:

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 :

Quote:
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!

Cheerrs
Eon
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 Question about obtaining built .dlls. A Z General 2 Mon Oct 15, 2018 4:11 am View latest post
No new posts OpenSceneGraph 3.0 for beginners book... NoeMurr General 5 Fri Oct 12, 2018 3:55 pm View latest post
No new posts OpenSceneGraph-3.6.3 stable release h... robertosfield General 0 Fri Sep 14, 2018 10:39 am View latest post
No new posts OpenSceneGraph-3.6.3 release candidate 3 robertosfield General 1 Thu Sep 13, 2018 8:03 am View latest post
No new posts OpenSceneGraph-3.6.3 release candidat... robertosfield General 15 Tue Sep 11, 2018 11:37 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