Processing pixel by pixel
Shaders are run on the GPU in parallel. GPUs require a different type of coding and therefore are written in a different language. We will be using the OpenGL Shader Language (GLSL), which looks very much like C/C++. For the specifications, see https://www.khronos.org/opengl/wiki/OpenGL_Shading_Language.
We will be creating a shader to process vertices and a shader to process fragments. Together, these will replace all the OpenGL drawing operations we’ve used to date. This will give you a chance to explore the movement of mathematical operations from the CPU to the GPU while at the same time understanding how mathematics principles transcend the graphics environment in which they are applied.
The first shader type we will explore is the vertex shader. This code processes one vertex at a time while running multiple versions of itself in parallel, each processing a different vertex. The simplest vertex shader that can be written is one that can...