10

I want to display mesh models in OpenGL ES 2.0, where it clearly shows the actual mesh, so I don't want smooth shading across each primitive/triangle. The only two options I can think about are

  1. Each triangle has its own set of normals, all perpendicular to the triangles surface (but then I guess I can't share vertices among the triangles with this option)
  2. Indicate triangle/primitive edges using black lines and stick to the normal way with shared vertices and one normal for each vertex

Does it have to be like this? Why can't I simply read in primitives and don't specify any normals and somehow let OpenGL ES 2.0 make a flat shade on each face?

Similar question Similar Stackoverflow question, but no suggestion to solution

Community
  • 1
  • 1
ChrHansen
  • 1,502
  • 1
  • 14
  • 22

1 Answers1

8

Because in order to have shading on your mesh (any, smooth or flat), you need a lighting model, and OpenGL ES can't guess it. There is no fixed pipeline in GL ES 2 so you can't use any built-in function that will do the job for you (using a built-in lighting model).

In flat shading, the whole triangle will be drawn with the same color, computed from the angle between its normal and the light source (Yes, you also need a light source, which could simply be the origin of the perspective view). This is why you need at least one normal per triangle.

Then, a GPU works in a very parallelized way, processing several vertices (and then fragments) at the same time. To be efficient, it can't share data among vertices. This is why you need to replicate normals for each vertex.

Also, your mesh can't share vertices among triangles anymore as you said, because they share only the vertex position, not the vertex normal. So you need to put 3 * NbTriangles vertices in you buffer, each one having one position and one normal. You can't either have the benefit of using triangle strips/fans, because none of your faces will have a common vertex with another one (because, again, different normals).

Benlitz
  • 1,952
  • 1
  • 17
  • 30
  • Is this also true of OpenGL (non-ES)? – Rick Dec 09 '15 at 08:13
  • OpenGL has a legacy fixed pipeline, but it is not recommended to use it. See this article for more information: https://www.opengl.org/wiki/Fixed_Function_Pipeline – Benlitz Dec 09 '15 at 09:32
  • Thank you. What I'm trying to get to is using SceneKit in OS X 10.10 (or 10.11) to pass an array of shared vertices, an array of indices for the triangles, and have it flat-shade that. Underneath it uses OpenGL or Metal, but I don't know enough about either. This author (http://ronnqvi.st/custom-scenekit-geometry/) seemed to think it wasn't something OpenGL could do, so I've been looking to see if it can, and that's how I found this SO question. – Rick Dec 09 '15 at 10:00