       cutPositions[cutPositionCount++] = newPos;
       vec4 c = newPos * 0.5f + vec4(0.5, 0.5f, 0.5f, 0);
       c.a = 0.5f;
-      emit(matrix * newPos, c);  // vec4(1, 1, 0, 1));
+      emittedVertexCount = emit(matrix * newPos, c, emittedVertexCount);  // vec4(1, 1, 0, 1));
     }
   }
 
-  if (triangleCount == 5)
-    emit(firstPosition, vec4(0, 1, 1, 1));
+  if (emittedVertexCount == 5)
+    emit(firstPosition, vec4(0, 1, 1, 1), emittedVertexCount);
 
   EndPrimitive();
 }


  vec4 center = gl_in[0].gl_Position;

  processSide(matrix, center, yAxis, xAxis, zAxis);
  processSide(matrix, center, xAxis, yAxis, zAxis);
  processSide(matrix, center, zAxis, xAxis, yAxis);
  processSide(matrix, center, -yAxis, xAxis, zAxis);
  processSide(matrix, center, -xAxis, yAxis, zAxis);
  processSide(matrix, center, -zAxis, xAxis, yAxis);

  for (int i = 0; i < cutPositionCount; ++i)
  {
    justEmit(cutPositions[i], vColor[0]);
  }
  EndPrimitive();
}


  EmitVertex();
}

int emit(vec4 pos, vec4 color, int emittedVertexCount)
{
  if (isFirst)
  {
