Shading with multiple positional lights
When shading with multiple light sources, we need to evaluate the reflection model for each light, and sum the results to determine the total light intensity reflected by a surface location. The natural choice is to create uniform arrays to store the position and intensity of each light. We'll use an array of structures so that we can store the values for multiple lights within a single uniform variable.
The following image shows a "pig" mesh rendered with five light sources of different colors. Note the multiple specular highlights:
Getting ready
Set up your OpenGL program with the vertex position in attribute location zero, and the normal in location one.
How to do it...
To create a shader program that renders using the Blinn-Phong reflection model with multiple light sources, use the following steps:
In the vertex shader, we'll use a similar structure as in the previous recipes, except we will use an array of structures for the lights. In addition, we...