   for (int i = 0; i < 3; ++i)
   {
     vec4 inPos = triangle[i];
-    bool isPosInFOV = dot(inPos, plane) > cutOffZ;
+    bool isPosInFOV = dot(inPos, nearPlane) > cutOffZ;
     if (isPosInFOV)
     {
       emittedVertexCount = emitWithPrimitiveHandling(

  cutPositions[cutPositionCount++] = newPos;
}

void processTriangle(const mat4 matrix, const vec4 triangle[3])
{
  const float cutOffZ = 0.5;
  int emittedVertexCount = 0;
  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]);

  float magnitude = sqrt(dot(plane.xyz, plane.xyz));
  plane = plane / magnitude;

  vec4 firstPosition;
  bool triangleSplittingNecessary = false;

  EndPrimitive();
}

void processSide(const mat4 matrix, const vec4 nearPlane, const vec4 center,
                 const vec4 side, const vec4 varying1, const vec4 varying2)
{
  vec4 triangle[3] = vec4[3](center + side - varying1 - varying2,
                             center + side - varying1 + varying2,
                             center + side + varying1 - varying2);
  processTriangle(matrix, nearPlane, triangle);

  triangle = vec4[3](center + side + varying1 - varying2,
                     center + side - varying1 + varying2,
                     center + side + varying1 + varying2);
  processTriangle(matrix, nearPlane, triangle);
}

bool hasSmallerAngle(const vec4 center, const vec4 pos1, const vec4 pos2)
