0
votes

At the moment im using one normal per vertex for my models, but that equates to having the model look rounded in terms of lighting, which is not ideal since my models are meant to have sharp edges. googling around shows me that its doesnt seem possible to use surface normals in opengl-es 2.0, but the alternative technique is to use multiple vertex normals per vertex to act as if you were using surface normals.

this would mean that the index buffer would need to be different for the normal array and the vertex array because for example, a cube would have 8 vertices, but each vertex would need 3 normals to act like surface normals (one for each connecting face of the cube, could need more if the model is triangulated which opengl-es requires). so the index array for vertices would be 8, and the index array for the normals would be 8x3=24.

does anyone know how to go about doing this?

at the moment my code looks like this

glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);

glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*sizeof(GLubyte), indices, GL_STATIC_DRAW);

glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribPosition);        
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

glGenBuffers(1, &_normalBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _normalBuffer);
glBufferData(GL_ARRAY_BUFFER, numNormals*sizeof(GLfloat), normals, GL_STATIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);
1
ok a suggestion has been to have no vertex sharing for my model, which should work, although is a bit of a crap way to do it if your model is really big, but mine have at most 20 vertices so it shouldnt be so bad. if i get it to work and no one has posted an answer ill write it up as an answerFonix

1 Answers

2
votes

You can't have multiple normals per vertex, and you can't have different indices for normals and position.

The only way to do this would be to duplicate your position data, and attach a different normal to each position.