   if (nextFragmentReadStatus)
   {
     finalColor = blend(finalColor, nextFragment.color);
-    if (finalColor.a > alphaThresholdForDepth &&
-        gl_FragDepth == DEPTH_NOT_SET)
+    if (finalColor.a > alphaThresholdForDepth)
     {
       setDepthFor(nextFragment.eyePos);
     }

      vec4 endPosCut_eye = segmentStartPos_eye + alpha * vec4(dir, 0);
      if (activeObjectCount > 0)
      {
        float depth = DEPTH_NOT_SET;
        fragmentColor = calculateColorOfVolumes(activeObjects, activeObjectCount,
            segmentStartPos_eye, endPosCut_eye, fragmentColor, depth);
        finalColor = finalColor + fragmentColor * (1.0f - finalColor.a);
        if (depth != DEPTH_NOT_SET)
          setDepth(depth);
      }

      setColorForLayer(layerIndex, finalColor);

  return ndcPos / ndcPos.w;
}

void setDepthFor(in vec4 positionInEyeSpace)
{
  if (gl_FragDepth != DEPTH_NOT_SET)
    return;

  vec4 ndcPos = fromEyeToNdcSpace(positionInEyeSpace);
  float depth = 0.5f * ndcPos.z + 0.5f;
  gl_FragDepth = depth;
}

void setColorForLayer(int layerIndex, vec4 color)
