   const vec4 yAxis = vec4(0, 0.5, 0, 0);
   const vec4 zAxis = vec4(0, 0, 0.5, 0);
 
+  vec4 nearPlane = 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(nearPlane.xyz, nearPlane.xyz));
+  nearPlane = nearPlane / magnitude;
   vec4 center = gl_in[0].gl_Position;
 
   // top
-  processSide(matrix, center, yAxis, xAxis, zAxis);
+  processSide(matrix, nearPlane, center, yAxis, xAxis, zAxis);
   // right
-  processSide(matrix, center, xAxis, yAxis, zAxis);
+  processSide(matrix, nearPlane, center, xAxis, yAxis, zAxis);
   // front
-  processSide(matrix, center, zAxis, xAxis, yAxis);
+  processSide(matrix, nearPlane, center, zAxis, xAxis, yAxis);
   // bottom
-  processSide(matrix, center, -yAxis, xAxis, zAxis);
+  processSide(matrix, nearPlane, center, -yAxis, xAxis, zAxis);
   // left
-  processSide(matrix, center, -xAxis, yAxis, zAxis);
+  processSide(matrix, nearPlane, center, -xAxis, yAxis, zAxis);
   // back
-  processSide(matrix, center, -zAxis, xAxis, yAxis);
+  processSide(matrix, nearPlane, center, -zAxis, xAxis, yAxis);
 
   fillHole(matrix);
 }

    }

    vec4 nextPos = triangle[(i + 1) % 3];
    bool isNextPosInFOV = dot(nextPos, plane) > cutOffZ;
    if ((isPosInFOV && !isNextPosInFOV) || (!isPosInFOV && isNextPosInFOV))
    {
      triangleSplittingNecessary = true;
      vec4 edge = inPos - nextPos;
      float lambda = (cutOffZ - dot(plane, inPos)) / dot(plane, edge);

      vec4 newPos = inPos + lambda * edge;
      addCutPositionIfNew(newPos);

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