 
 void setPositionNdc(in int layerIndex, in vec4 positionNdc)
 {
+  if (gl_FragDepth == DEPTH_NOT_SET)
+    gl_FragDepth = positionNdc.z;
+
   if (layerIndex == 0)
     position = positionNdc;
   else if (layerIndex == 1)

      setColorForLayer(layerIndex, finalColor);
      if (getDepth(layerIndex) == DEPTH_NOT_SET)
        setPositionNdc(layerIndex, vec4(1));
      finalColor = vec4(0);
      ++layerIndex;
      endDistance = dot(nextFragment.eyePos, layerPlanes[layerIndex]);


  uvec2 ij = uvec2(pos.xy);

  gl_FragDepth = DEPTH_NOT_SET;
  position = vec4(1, 0, DEPTH_NOT_SET, 1);
  position2 = vec4(1, 0, DEPTH_NOT_SET, 1);
  position3 = vec4(1, 0, DEPTH_NOT_SET, 1);
