How it works...

Within the vertex shader, the lighting parameters are stored in the uniform array lights. Each element of the array is a struct of type LightInfo. This example uses five lights. The diffuse/specular light intensity is stored in the L field, the ambient intensity is stored in the La field, and the position in camera coordinates is stored in the Position field.

The rest of the uniform variables are essentially the same as in the Phong model shader presented in Chapter 3, The Basics of GLSL Shaders.

The phongModel function is responsible for computing the shading equation for a given light source. The index of the light is provided as the first parameter, light. The equation is computed based on the values in the lights array ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.