2
votes

In the default mesh vertex construction we do this.

//v = vertex, p = position, c = color
buffer = { v0 , p0, c0,
           v1 , p0, c0,
           v2 , p0, c0  };

And we have an triangle. But I want to reuse the obvious attributes something like this:

//p and c are the same for all vertexes
buffer = { v0, p0, c0 ,
           v1, 
           v2 };

We can do this with uniform values on the shader, but i will render thousands of triangles with different positions on the same buffer:

buffer = { v0, p0, c0 ,
           v1, 
           v2,
           v3, p1, c1,
           v4,
           v5, 
           v6, p2, c2,
           ...};

My solutions for now is:

1) Send a copy of attributes for each vertex like first example (don´t want to, but may be the best solution).

2) Send an index attribute(for search) and uniform array for position/color (Uniform size limit problem?)

3) Best solution?

2
The performance loss for the (very minor) memory benefit of doing this is generally not worth it, there's no clean way of doing this. And with most models that you load in, you're going to have mostly unique texture coordinates and normals. - Robert Rouhani
This really seems like false economy to me. I'd worry more about GPU efficiency before worrying about a bit of 'redundant' data. Compared to texture memory requirements, it's nothing. - Brett Hale
In addition to (or in spite of!) what I said before, you might find provoking vertex to be of some use. - Brett Hale
Your question doesn't make sense. A position is part of the vertex; it is a component of the vertex. So what part of v0 is different from v1 if you don't change the position or the color. In short, what do you mean by "vertex" here? - Nicol Bolas
What i mean is: A triangle have 3 point that define their model. I can send 3 position, or 3 color or whatever. But normaly these 3 positions are the same for the 3 points of the triangle. And I want to know if there is a way to reduce this redudance of positions(or color, etc). When sending for eg. one thousand of triangles i´m sending 3 thousands of points and the same size of positions, colors etc. If you use one position per triangle you cut this by 2/3. Since I will work with probably millions of triangles, cutting 2 millions of floats seems a good idea ;p - Patric

2 Answers

3
votes
//p and c are the same for all vertexes

No, they are not. A vertex is the whole combination of v, p and c in your case. Change one of them, and you got an entirely different vertex. Common misconception, but that's how it works

2
votes

Assuming you are not on an ancient hardware, and vertex memory isn't really that significant, just copy the data and keep each vertex with a full set of attributes. It certainly won't be slower.

"Reusing" data in such a way usually results in a perfomance drop, because GPU can't optimize the data access; it has to do complicated things you want to do instead.