     return position4.z;
 }
 
+void setPositionNdcToEndValue(in int layerIndex)
+{
+  if (layerIndex == 0)
+  {
+    position = vec4(1);
+  }
+  else if (layerIndex == 1)
+  {
+    position2 = vec4(1);
+  }
+  else if (layerIndex == 2)
+  {
+    position3 = vec4(1);
+  }
+  else
+  {
+    position4 = vec4(1);
+  }
+}
+
 void setPositionNdc(in int layerIndex, in vec4 positionNdc)
 {
   if (gl_FragDepth == DEPTH_NOT_SET)

            segmentStartPos_eye, endPosCut_eye, fragmentColor, depth);
        finalColor = finalColor + fragmentColor * (1.0f - finalColor.a);
        if (depth == DEPTH_NOT_SET)
          depth = 1.0;

        setPositionNdc(layerIndex, vec4(depth, depth, depth, 1));
      }
      else
      {
        setPositionNdc(layerIndex, vec4(1));
      }

      setColorForLayer(layerIndex, finalColor);


  setColorForLayer(layerIndex, finalColor);
  if (getDepth(layerIndex) == DEPTH_NOT_SET)
    setPositionNdcToEndValue(layerIndex);

  for (++layerIndex; layerIndex < layerCount; ++layerIndex)
  {
    setColorForLayer(layerIndex, vec4(0));
    setPositionNdcToEndValue(layerIndex);
  }

  if (gl_FragDepth == DEPTH_NOT_SET)
    gl_FragDepth = 1.0;
}

