 
     if (objectId == 0 && fragmentColor.a > alphaThresholdForDepth)
     {
-      gl_FragDepth = fromEyeToNdcSpace(currentFragment.eyePos).z;
       setPositionAndDepthFor(layerIndex, currentFragment.eyePos);
     }
 

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

    // early ray termination


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)
