Sign in to follow this  
kakkeli12

gldrawelements vertex duplicates

Recommended Posts

kakkeli12    122
Hello! Is there any other way to pass per-face data to vertex shaders other than creating 3 unique vertices for every single triangle and start using gldrawarrays instead of gldrawelements? Currently i have some duplicated vertices because of unique normals and texture coordinates but fortunately that doesn't really add too many extra vertices. However I'm going to add bump mapping which requires tangent-space transformation matrix per-face and without better solution to this i have 4x more vertices and also bigger vertex structs because of the extra vectors. Vertex shader seems to be a logical choice for this lightsource to tangent-space transformation.

Share this post


Link to post
Share on other sites
V-man    813
You could do



glNormal3f();
gldrawelements();

glNormal3f();
gldrawelements();

glNormal3f();
gldrawelements();



but that will increase the number of calls to gldrawelements.
It's most likely better to duplicate vertices.

Share this post


Link to post
Share on other sites
kakkeli12    122
Quote:
Original post by V-man
but that will increase the number of calls to gldrawelements.
It's most likely better to duplicate vertices.


Well that would make something like 924 (or whatever object face count is) gldrawelements-calls. :) Also duplicating vertices isn't just duplicating, it's going to triple the number of vertices from something like 462 to 2772. Isn't there any better way or am I worrying about this too much?

Share this post


Link to post
Share on other sites
kakkeli12    122
Quote:
Original post by Brother Bob
With the number of vertices you're talking about, you're worrying about it WAAAY too much.


Yeah, probably. But how games with higher polycounts do things like this?

Share this post


Link to post
Share on other sites
V-man    813
Quote:
Original post by kakkeli12
Quote:
Original post by Brother Bob
With the number of vertices you're talking about, you're worrying about it WAAAY too much.


Yeah, probably. But how games with higher polycounts do things like this?


It depends on the object. With most object, vertex, texcoord, normals, tangent, binormal......... are shared. So the vertex count stays low while triangle count stays high. They also optimize the mesh with offline software so that post transform cache is well utilized.

So it is not a problem for most games. The problem for games is fillrate or even the CPU.

What are you rendering?

Share this post


Link to post
Share on other sites
RobTheBloke    2553
Quote:
Original post by kakkeli12However I'm going to add bump mapping which requires tangent-space transformation matrix per-face and without better solution to this i have 4x more vertices and also bigger vertex structs because of the extra vectors.


don't you mean Tangent Space Matrix per vertex? i.e. If a vertex, it's normal and UV coord are shared, then the tangent and bi-normal will be the same also. The number of vertices should not be increasing because you are storing a TBN matrix instead of just the normal??

Ok, so your vertex data size will jump from


struct VData {
float vertex[3];
float normal[3];
float uv[2];
};


to


struct VData {
float vertex[3];
float normal[3];
float tangent[3];
float binormal[3];
float uv[2];
};


but that's not a big deal. You can always use a vertex shader to calculate the bi-normal by doing a cross product with the tangent and normal, leaving you with


struct VData {
float vertex[3];
float normal[3];
float tangent[3];
float uv[2];
};


Unless i have missed something?

Share this post


Link to post
Share on other sites
kakkeli12    122
Quote:
Original post by V-man
What are you rendering?


Game objects, map elements and stuff. Not much polygons right now but might change in future. And i'd like to know how to make things right away!

RobTheBloke:
That sounds reasonable. I thought tangent space matrix must be per-face to correctly scale the vectors for bump mapping?

Share this post


Link to post
Share on other sites
zedz    291
>> I thought tangent space matrix must be per-face to correctly scale the vectors for bump mapping?

no, use a different mat33 per vertex

>> But how games with higher polycounts do things like this?

most/all games have duplicated vertices, characters in recent games are from 5000->30000 verts.
1000 verts for a character is quake3 era

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this