How to do it...

To modify the Phong reflection model to use flat shading, take the following steps:

  1. Use the same vertex shader as in the Phong example provided earlier. Change the output variable LightIntensity as follows:
flat out vec3 LightIntensity; 
  1. Change the corresponding variable in the fragment shader to use the flat qualifier:
flat in vec3 LightIntensity; 
  1. Compile and link both shaders within the OpenGL application, and install the shader program prior to rendering.

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.