 
 void setPositionAndDepth(vec4 positionInEyeSpace)
 {
-  vec4 ndcPos = projectionMatrix * positionInEyeSpace;
-  ndcPos = ndcPos / ndcPos.w;
-  float depth = ndcPos.z;
-  gl_FragDepth = depth;
-  position.xyz = ndcPos.xyz;
-  position.w = 1.0f;
+  if (position.w == POSITION_NOT_SET)
+  {
+    vec4 ndcPos = projectionMatrix * positionInEyeSpace;
+    ndcPos = ndcPos / ndcPos.w;
+    float depth = ndcPos.z;
+    gl_FragDepth = depth;
+    position.xyz = ndcPos.xyz;
+    position.w = 1.0f;
+  }
 }
 
 vec4 calculateSampleColor(in uint remainingActiveObjects, in int activeObjectCount,

    updateActiveObjects(objectId, activeObjects);
    int activeObjectCount = bitCount(activeObjects);

    if (objectId == 0 && fragmentColor.w > alphaThresholdForDepth &&
        position.w == POSITION_NOT_SET)
    {
      setPositionAndDepth(currentFragment.eyePos);
    }

    // sample accumulation
    fragmentColor = fragmentColor + sampleColor * (1.0f - fragmentColor.w);

    if (fragmentColor.w > alphaThresholdForDepth)
    {
      setPositionAndDepth(vec4(startPos_eye, 1));
    }
