   EmitVertex();
 }
 
-void emit(vec4 pos, vec4 color)
+int emit(vec4 pos, vec4 color, int emittedVertexCount)
 {
   if (isFirst)
   {

    if (isPosInFOV)
    {
      vec4 c = inPos * 0.5f + vec4(0.5, 0.5f, 0.5f, 0);
      c.a = 1.0f;
      c.rgb = plane.xyz / magnitude * 0.5 + vec3(0.5, 0.5, 0.5);
      emit(matrix * inPos, c);  // vColor[0]);
    }
    vec4 nextPos = triangle[(i + 1) % 3];
    bool isNextPosInFOV = dot(nextPos, plane) > cutOffZ;

  }

  justEmit(pos, color);
  ++emittedVertexCount;

  if (emittedVertexCount == 3)
  {
    EndPrimitive();
    if (hasTwoTriangles)
    {
      justEmit(pos, color);
      ++emittedVertexCount;
    }
  }

  return emittedVertexCount;
}

void processTriangle(mat4 matrix, vec4 triangle[3])
{
  const float cutOffZ = 0.5;
  int emittedVertexCount = 0;
  isFirst = true;
  hasTwoTriangles = false;
  vec4 plane = vec4(matrix[0][3] + matrix[0][2], matrix[1][3] + matrix[1][2],
                    matrix[2][3] + matrix[2][2], matrix[3][3] + matrix[3][2]);

