 
   setColorForLayer(layerIndex, finalColor);
   if (getDepth(layerIndex) == DEPTH_NOT_SET)
-    setPositionNdc(layerIndex, vec4(1));
+    setPositionNdcToEndValue(layerIndex);
 
   for (++layerIndex; layerIndex < layerCount; ++layerIndex)
   {
     setColorForLayer(layerIndex, vec4(0));
-    setPositionNdc(layerIndex, vec4(1));
-  }
-}
-
+    setPositionNdcToEndValue(layerIndex);
+  }
+
+  if (gl_FragDepth == DEPTH_NOT_SET)
+    gl_FragDepth = 1.0;
+}
+

    {
      setColorForLayer(layerIndex, finalColor);
      if (getDepth(layerIndex) == DEPTH_NOT_SET)
        setPositionNdc(layerIndex, vec4(1));

      finalColor = vec4(0);
      ++layerIndex;

    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)
