Flat shading is the simplest shading model, which calculates the illumination at a single point for each polygon (or polygon vertices in OpenGL). This means that the color is the same for all points of each polygon.

Advantages

  • Fast: a single computation per polygon (or one per polygon vertex in OpenGL).

Disadvantages

  • Inaccurate.
  • Discontinuities at polygon boundaries.

Implementation

GLSL has the keyword flat to skip interpolation.

// vertex shader
flat out vec4 polygon_color;
void main() {
  // ...
  polygon_color = vec4(ambient + diffuse + specular, 1.0);
}

// fragment shader
flat in vec4 polygon_color;
out vec4 color;
void main () {
  color = polygon_color;
}