2

In opengl or opengl-es you can use indices to share a vertices. This works fine if you are only using vertex coords and texture coords that don't change, but when using normals, the normal on a vertex may change depending on the face. Does this mean that you are essentially forced to scrap vertex sharing in opengl? This article http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/ seems to imply that this is the case, but I wanted a second opinion. I'm using .obj models so should I just forget about trying to share verts? This seems like it would increase the size of my model though as I iterate and recreate the array since i am repeating tons of verts and their tex/normal attributes.

genpfault
  • 51,148
  • 11
  • 85
  • 139
NJGUY
  • 2,045
  • 3
  • 23
  • 43

2 Answers2

0

The link you posted explains the situation well. I had the same question in my mind couple months ago.I remember I read that tutorial.

If you need exactly 2 different normal, so you should add that vertex twice in your index list. For example, if your mesh is a cube you should add your vertices twice.

Otherwise indexing one vertex and calculating an average normal is kind of smoothing your normal transitions on your mesh. For example if your mesh is a terrain or a detailed player model etc. you can use this technique which you save free space and get better looking result.

If you ask how to calculate average normal, I used average normal calculating algorithm from this question and result is fast and good.

Community
  • 1
  • 1
Berke Cagkan Toptas
  • 1,034
  • 3
  • 21
  • 31
0

If the normals are flat faces then you can annotate the varying use in the fragment shader with the "flat" qualifier. This means only the value from the provoking vertex is used. With a good model exporter you can get relatively good vertex sharing with this.

Not sure on availability on GLES2, but is part of GLES3.

Example: imagine two triangles, expressed as a tri-strip:

V0 - Norm0 
V1 - Norm1 
V2 - Norm2
V2 - Norm3

Your two triangles will be V0/1/2 and V1/2/3. If you mark the varying variable for the normal as "flat" then the first triangle will use Norm0 and the second triangle will use Norm1 (i.e. only the first vertex in the triangle - known as the provoking vertex - needs to have the correct normal). This means that you can safely reuse vertices in other triangles, even if the normal is "wrong" provides that you make sure that it isn't the provoking vertex for that triangle.

solidpixel
  • 10,688
  • 1
  • 20
  • 33