     endPos_eye = nextFragmentReadStatus ?
       nextFragment.eyePos : segmentStartPos_eye;
 
+    vec4 world = inverseViewMatrix * vec4(endPos_eye, 1);
+    float dist = dot(world, farPlane);
+    if (dist < 0)
+    {
+      endPos_eye = world.xyz - dist * farPlane.xyz;
+      nextFragmentReadStatus = false;
+      // to prevent case of maxAge == 1 at the end
+      age = ++maxAge;
+      if (activeObjectCount == 0)
+        break;
+    }
+
     if (activeObjectCount > 0)
     {
       fragmentColor = calculateColorOfVolumes(activeObjects, activeObjectCount,

  if (maxAge == 0)
    discard;  // no fragment, early exit

  int activeObjects = 0;
  FragmentData currentFragment;
  FragmentData nextFragment;

uniform vec3 textureAtlasSize;
uniform vec3 sampleDistance;
uniform float alphaThresholdForDepth = 0.1;
uniform float depthCutOff = 0.0;

uniform sampler3D volumeSampler;

