Chapter 2. The Basics of GLSL Shaders
In this chapter, we will cover:
- Implementing diffuse, per-vertex shading with a single point light source
- Implementing per-vertex ambient, diffuse, and specular (ADS) shading
- Using functions in shaders
- Implementing two-sided shading
- Implementing flat shading
- Using subroutines to select shader functionality
- Discarding fragments to create a perforated look
Introduction
Shaders were first added into OpenGL in Version 2.0, introducing programmability into the formerly fixed-function OpenGL pipeline. Shaders give us the power to implement alternative rendering algorithms and a greater degree of flexibility in the implementation of those techniques. With shaders, we can run custom code directly on the GPU, providing us with the opportunity to leverage the high degree of parallelism available with modern GPUs.
Shaders are implemented using the OpenGL Shading Language (GLSL). The GLSL is syntactically similar to C, which should make it easier for experienced...