1
votes

I'm writing a WebGL program that draws a bunch of triangles to the screen. I'm using indirect addressing, so something like this:

gl.drawElements(gl.TRIANGLES, list.length, gl.UNSIGNED_SHORT, 0);

Is there any way for the vertex shader to know which vertex of a triangle it is processing? (among the three vertices in the order given by the list, i.e., the first, second or last)

1

1 Answers

1
votes

You can use additional integer attribute in stride alongside with vertex coordinates, texture coordinates, normal, etc. to check ID of vertex.

If you target OpenGL ES 3+ you can use gl_VertexID - https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/gl_VertexID.xhtml