When shading with multiple light sources, we need to evaluate the shading equation 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 figure shows a "pig" mesh rendered with five light sources of different colors. Note the multiple specular highlights.
Set up your OpenGL program with the vertex position in attribute location zero, and the normal in location one.
To create a shader program that renders using the ADS (Phong) shading model with multiple light sources, use the following steps:
Use the following vertex shader:
layout (location = 0) in vec3 VertexPosition; layout (location = 1) in vec3 VertexNormal; out vec3 Color; struct LightInfo...