Shaders

The GPU can not draw anything until programmed to do so. We'll look at GPU programming in depth later. For now, we'll use an extremely simple pair of shaders without fully understanding how or why they do what they do.

〈Vertex Shader〉 ≡
  precision mediump float;
  attribute vec4 vertexPosition;
  void main() {
    gl_Position = vertexPosition;
  }

The vertex shader provides an opportunity for the GPU to process the attributes of each vertex that is drawn. For the minimal application, the vertex shader simply copies the vertex position attribute to its output.

〈Fragment Shader〉 ≡
  void main() {
    gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
  }

The fragment shader provides an opportunity for the GPU to process each fragment, a.k.a pixel, that is draw. For the minimal application, the fragment shader simply writes the color yellow to its output.