   }
 
   vec4 world = inverseViewMatrix * endPos_eye;
-  float endDistance = dot(world, farPlane);
+  float endDistance = dot(world, layerPlane1);
   if (endDistance < 0)
   {
-    setPositionAndDepth(viewMatrix * vec4(world.xyz - endDistance * farPlane.xyz, 1.0f));
+    setPositionAndDepth(viewMatrix * vec4(world.xyz - endDistance * layerPlane1.xyz, 1.0f));
     outputColor = vec4(0);
+  }
+  endDistance = dot(world, layerPlane2);
+  if (endDistance < 0)
+  {
+    setPositionAndDepth(viewMatrix * vec4(world.xyz - endDistance * layerPlane2.xyz, 1.0f));
+    outputColor2 = vec4(0);
+  }
+  endDistance = dot(world, layerPlane3);
+  if (endDistance < 0)
+  {
+    setPositionAndDepth(viewMatrix * vec4(world.xyz - endDistance * layerPlane3.xyz, 1.0f));
+    outputColor3 = vec4(0);
   }
 
   for (--age; age < maxAge; age++)  // all fragments

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

uniform sampler3D volumeSampler;


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

  vec4 layerPlane1 = vec4(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2], layerCuts.x);
  vec4 layerPlane2 = vec4(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2], layerCuts.y);
  vec4 layerPlane3 = vec4(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2], layerCuts.z);

  int activeObjects = 0;
  FragmentData currentFragment;
