# Combining varying vertex variable and vertex variable in OpenGL. How to? [duplicate]

Let's say I have 2 triangles sharing an edge defined by 4 vertices. Though the normals for these 2 triangles are unique for each triangle and are defined per vertex. So say I have 4 vertices, 6 normals (as shown in the figure below).

I would like to know how this can be dealt with in OpenGL? I have been using glDrawElement so far, but I understand that this would only work if I had 4 normals (1 normal per vertex) and this it wouldn't allow me to define 3 normals per triangle.

What's the best/common/most efficient of dealing with this case? Do I need to also duplicate the vertices (3 unique vertices per triangle or is there a more clever solution to this?) so that I have as many vertices than I have normals?

• @Kromster: yes you are right this seems to be the same question. The person answering the question suggests something though "otherwise have unique attributes other than position" but doesn't explain how this would work. Any idea? – user18490 Feb 27 '17 at 18:31
• This is misunderstanding. "You'll have to duplicate the vertices you want to participate in different triangles or otherwise have unique attributes other than position." - Josh means that you have to duplicate the vertices if you want "to participate in different triangles" OR if you want to "have unique attributes other than position". – Kromster Feb 27 '17 at 18:46

## 1 Answer

Yes, you do need to duplicate vertices.

Oftentimes this is required by normals. Another often reason - UV maps, Surfaces.

I come to think of vertices not as points in 3D space, but as "unique set of properties" placed in 3D space. These "sets" often take the same space, but lines and triangles using them - each take their "sets".

• Ok great thanks for the answer. But is this efficient though. This means I will have 6 vertices instead of 4. That's okay with 2 triangles but not as good when the mesh is very large? What do you think? – user18490 Feb 27 '17 at 18:06
• I doubt there are simple optimizations over that. GPUs are great at crunching data. But let's see for other answers. – Kromster Feb 27 '17 at 18:14
• @user18490 - if you think about it, vertex count is only one part of the graphics pipeline, and really just the front-end part that your application deals with. You're very unlikely to be bottlenecked on vertex count; typically you will be drawing many more fragments than vertices. Don't worry about it, if you have to duplicate the data then duplicate the data; it's actually often far more efficient to burn a little extra memory than it is to try some tricksy scheme that doesn't align well with the way GPUs like to work. – Maximus Minimus Feb 27 '17 at 19:05