   return ndcPos / ndcPos.w;
 }
 
-void setPositionAndDepth(in vec4 positionInEyeSpace)
-{
-  if (position.w == POSITION_NOT_SET)
-  {
-    vec4 ndcPos = fromEyeToNdcSpace(positionInEyeSpace);
-    gl_FragDepth = ndcPos.z;
+void setPositionAndDepthFor(in int layerIndex, in vec4 positionInEyeSpace)
+{
+  vec4 ndcPos = fromEyeToNdcSpace(positionInEyeSpace);
+  if (layerIndex == 0)
     position = ndcPos;
-  }
-  else if (position2.w == POSITION_NOT_SET)
-  {
-    vec4 ndcPos = fromEyeToNdcSpace(positionInEyeSpace);
+  else if (layerIndex == 1)
     position2 = ndcPos;
-  }
+  else if (layerIndex == 2)
+    position3 = ndcPos;
+  else if (layerIndex == 2)
+    position4 = ndcPos;
+
+  // TODO depth
 }
 
 void setColorForLayer(int layerIndex, vec4 color)

  float endDistance = dot(world, layerPlanes[layerIndex]);
  while (endDistance < 0)
  {
    setPositionAndDepth(viewMatrix *
                        vec4(world.xyz - endDistance * layerPlanes[layerIndex].xyz, 1.0f));
    setColorForLayer(layerIndex, vec4(0));
    ++layerIndex;
    endDistance = dot(world, layerPlanes[layerIndex]);


uniform sampler3D volumeSampler;

#define transferFunctionRowCount 64.0f

struct VolumeData
