1
\$\begingroup\$

This question already has an answer here:

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

enter image description here

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?

\$\endgroup\$

marked as duplicate by Kromster says support Monica, DMGregory, Community Feb 27 '17 at 22:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ @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? \$\endgroup\$ – user18490 Feb 27 '17 at 18:31
  • 1
    \$\begingroup\$ 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". \$\endgroup\$ – Kromster says support Monica Feb 27 '17 at 18:46
2
\$\begingroup\$

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".

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – user18490 Feb 27 '17 at 18:06
  • \$\begingroup\$ I doubt there are simple optimizations over that. GPUs are great at crunching data. But let's see for other answers. \$\endgroup\$ – Kromster says support Monica Feb 27 '17 at 18:14
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Maximus Minimus Feb 27 '17 at 19:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.