       nextFragment.eyePos : segmentStartPos_eye;
 
     vec4 world = inverseViewMatrix * endPos_eye;
-    float dist = dot(world, farPlane);
-    if (dist < 0)
-    {
-      vec4 endPosCut_eye = endPos_eye; //viewMatrix * vec4(world.xyz - dist * farPlane.xyz, 1.0f);
+    endDistance = dot(world, farPlane);
+    if (startDistance > 0 && endDistance < 0)
+    {
+      vec4 endPosCut_eye = viewMatrix * vec4(world.xyz - endDistance * farPlane.xyz, 1.0f);
       /*
       nextFragmentReadStatus = false;
       // to prevent case of maxAge == 1 at the end

  }

  vec4 world = inverseViewMatrix * endPos_eye;
  float dist = dot(world, farPlane);
  if (dist < 0)
  {
    setPositionAndDepth(viewMatrix * vec4(world.xyz - dist * farPlane.xyz, 1.0f));
    outputColor = vec4(backgroundColor, 1);
    /*
    // to prevent case of maxAge == 1 at the end

      {
        finalColor = blend(finalColor, currentFragment.color);
      }
      setPositionAndDepth(endPosCut_eye);
      outputColor = blend(clamp(finalColor, vec4(0.0), vec4(1.0)), vec4(backgroundColor, 1.0));
      segmentStartPos_eye = endPosCut_eye;
    }

    if (activeObjectCount > 0)
    {
