0
votes

So, I am working on an OpenGL ES 2.0 terrain rendering program still. I have weird drawing happening at the tops of ridges. I am guessing this is due to surface normals not being applied.

So, I have calculated normals. I know that in other versions of OpenGL you can just activate the normal array and it will be used for culling. To use normals in OpenGL ES can I just activate the normals or do I have to use a lighting algorithm within the shader?

Thanks

1
Are you able to supply any screenshots?Tommy
On SO, computer graphics is more a niche. However, a picture may tell more than a thousand words to seasoned devs.Sebastian Mach

1 Answers

0
votes

OpenGL doesn't use normals for culling. It culls based on whether the projected triangle has its vertices arranged clockwise or anticlockwise. The specific decision is based on (i) which way around you said was considered to be front-facing via glFrontFace; (ii) which of front-facing and/or back-facing triangles you asked to be culled via glCullFace; and (iii) whether culling is enabled at all via glEnable/glDisable.

Culling is identical in both ES 1.x and 2.x. It's a fixed hardware feature. It's external to the programmable pipeline (and, indeed, would be hard to reproduce within the ES 2.x programmable pipeline because there's no shader with per-triangle oversight).

If you don't have culling enabled then you are more likely to see depth-buffer fighting at ridges as the face with its back to the camera and the face with its front to the camera have very similar depths close to the ridge and limited precision can make them impossible to distinguish correctly.

Lighting in ES 1.x is calculated from the normals. Per-vertex lighting can produce weird problems at hard ridges because normals at vertices are usually the average of those at the faces that join at that vertex, so e.g. a fixed mesh shaped like \/\/\/\/\ ends up with exactly the same normal at every vertex. But if you're not using 1.x then that won't be what's happening.

To implement lighting in ES 2.x you need to do so within your shader. As a result of that, and of normals not being used for any other purpose, there is no formal way to specify normals as anything special. They're just another vertex attribute and you can do with them as you wish.