 
     if (activeObjectCount > 0)
     {
+      float depth;
       fragmentColor = calculateColorOfVolumes(activeObjects, activeObjectCount,
-          segmentStartPos_eye, endPos_eye, fragmentColor);
+          segmentStartPos_eye, endPos_eye, fragmentColor, depth);
       finalColor = finalColor + fragmentColor * (1.0f - finalColor.a);
+
+      setPositionNdc(layerIndex, vec4(0, 0, depth, 1));
     }
     else
     {

      vec4 endPosCut_eye = viewMatrix * (startWorld + alpha * vec4(dir, 0));
      if (activeObjectCount > 0)
      {
        fragmentColor = calculateColorOfVolumes(activeObjects, activeObjectCount,
            segmentStartPos_eye, endPosCut_eye, fragmentColor);
        finalColor = finalColor + fragmentColor * (1.0f - finalColor.a);
      }
      setPositionAndDepthFor(layerIndex, endPosCut_eye);
      setColorForLayer(layerIndex, clamp(finalColor, vec4(0.0), vec4(1.0)));
      finalColor = vec4(0);
      fragmentColor = vec4(0);


    if (fragmentColor.a > alphaThresholdForDepth)
    {
      depth = fromEyeToNdcSpace(startPos_eye).z;
      gl_FragDepth = fromEyeToNdcSpace(startPos_eye).z;
    }

