The effect I want to achieve is vertex color with sharp contours. So inside the triangle the fragment shader should use the color of whatever vertex is closest to that fragm
[replaced incorrect original]
This should actually work...
//vert
out vec3 colour;
...
//geom
//simple passthrough but dupe colours to separate and include barycentric coord
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in vec3 colour[];
flat out vec3 colours[3];
out vec3 coord;
...
for (int i = 0; i < 3; ++i)
colours[i] = colour[i];
for (int i = 0; i < 3; ++i)
{
coord = vec3(0.0);
coord[i] = 1.0;
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
//frag
flat in vec3 colours[3]; //triangle's 3 vertex colours
in vec3 coord; //barycentric weights as a result of interp
...
//get index of biggest coord
int i = (coord.x > cood.y && coord.x > coord.z) ? 0 :
((coord.y > coord.z) ? 1 : 2);
//choose that colour
vec3 fragColour = colours[i];