The Vertex Shader

A very simple shader that copies the input to the output.

129                 // A Vertex shader does per vertex computations. Here we set the predefined variable
130                 // gl_Position to the position of the vertex. We will see many uses for the vertex shader later.
131                 // For example, vertices can be moved in the vertex shader, producing animation or motion.
132                 // When you move through a 3D game, you are seeing the effects of a vertex shader moving the
133                 // polygons around.
134                 var vertexShaderSource   = "attribute vec3 position;"
135                                            + ""
136                                            + "void main()"
137                                            + "{"
138                                            + "    gl_Position = vec4(position, 1);"
139                                            + "}";

(0,1) (-1,-1) (1,-1)

Notes

Shaders are small programs written in the GL Shading Language, GLSL. That position is an attribute marks it as an input to the program. A vec3 is what it sounds like, a three element vector, or array.

This program copies the input variable to the predefined output variable gl_Position. gl_Position holds the position of the vertex in homogeneous coordinates.