Disable color interpolation in GLSL

Viewed 98

Consider a triangle in OpenGL or Vulkan with 2 of its vertices being green and one blue. Is there a way to disable the interpolation that GLSL does, and have the color of the entire triangle be green since there are more green vertices than blue ones?

I've heard something about the flat qualifier, but I'm not too sure if that is what I need.

1 Answers

Yes it is. See Interpolation qualifiers:

flat
The value will not be interpolated. The value given to the fragment shader is the value from the Provoking Vertex for that primitive.

That means if you use the flat interpolation qualifier for your color attributes, all fragments of the primitive get the same color.

Vertex shader:

flat out vec4 color;

Fragment shader

flat in vec4 color;
Related