How to do it...

To create a shader program that implements the Phong reflection model using a directional light source, we'll use the same vertex shader as in the previous recipe, except with a single light source.  Within the phongModel function, replace the calculation of the s vector with the following: 

vec3 s;if( Light.Position.w == 0.0 )  s = normalize( Light.Position.xyz );else  s = normalize( Light.Position.xyz - position );

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.