   return segmentTextureLength;
 }
 
+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;
+}
+
 void main()
 {
   o_PixColor = vec4(0);


        if (fragmentColor.w > 0.1 && position.w == -2)
        {
          vec4 ndcPos = projectionMatrix * vec4(startPos_eye, 1);
          ndcPos = ndcPos / ndcPos.w;
          float depth = ndcPos.z;
          gl_FragDepth = depth;
          position.xyz = ndcPos.xyz;
          position.w = 1.0f;
        }
        // early ray termination
        if (fragmentColor.w > 0.999)
          break;


    if (nextFragmentReadStatus && objectId == 0 && position.w == -2)
    {
      setPositionAndDepth(currentFragment.eyePos);
    }

    // fetch next Fragment
