0
votes

I like to generate flat shading triangle normales in the vertex shader. To do this, I need to access the current, and the two next vertices attributes in the current vertex shader. Obviously this can be done by a geometry shader, but those don't exist in GL ES for example.

So is there any way to make GLSL access three consecutive vertex positions, but only advance by one position in every vertex invocation? Otherwise I would have to assign the data of three vertices to every vertex.. a vast overhead.

1
Why don't you pre-calculate that normal/color, and store it in the buffer as well as the vertices? - vallentin
I don't like to store all the normals that can easily be obtained by the triangles vertex position... Even if I store them, I would only have one normal for three vertices, so how to access them 3 times? The same problem... - dronus

1 Answers

0
votes

Accessing multiple vertices isn't possible in the vertex shader. If you want to create flat shading, you need to replicate your vertices, so that you have a seperate copy of the vertex for each surface normal you will need (one for each face that shares that vertex position). This is probably the solution you'd need for OpenGL ES.

Alternatively, if you are targeting OpenGL 4.x you can use the concept of the provoking vertex, which allows you to specify a vertex for which the attributes should be re-used across all the vertices of the face. The attributes affected are only those which have the flat keyword associated with them in the shader source.