Vertex shader

cosmos 2nd July 2017 at 10:15pm
Shader

Takes a certain representation of a Scene, usually as Points (vertices), and transforms this vertices into another representation which is useful for latter processing. For instance, in OpenGL/WebGL, your vertices can be transformed to what is called clipspace, using 4d Homogeneous coordinates, which are then automatically processed to project them as 2d points in the device screen. This process is know as the Camera transform (see also Camera (computer graphics) for further steps)

The 2d pixel coordinates corresponding to the vertices, as well as to all points inside the polygon primitives (often triangles) that go with those vertices, are often passed to the Fragment shader, to decide which color they should appear as.

Here is a common procedure done by a vertex shader, to transform coordinates to those in clipspace: WebGL model view projection.

As explained here, the clipspace coordinates are then transformed to pixel coordinates: gl_Position is the (4d) position of a vertex, while gl_FragCoord is the (2d) position of a fragment.

The operations that happen in between are

  1. primitive assembly (to generate a triangle from 3 vertices, e.g.)
  2. clipping (i.e. cut the triangle in multiple triangles that are all on inside the view, if it does not initially fit)
  3. viewport application
  4. Rasterization (take those triangles and generate covered fragments from them).

In WebGL, one can set the viewport, as gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);, see here