 
   if (maxage == 1)
   {
-    next_fragment_read_status = fetchFragment(ij, 1, next_fragment);    
+    next_fragment_read_status = fetchFragment(ij, 1, next_fragment);
   }
 
   if (next_fragment_read_status)


    discard;  // no fragment, early exit
  }


  int activeobjects = 0;
  int activeobjectcount = 0;


    dirvec_eye = endpos_eye - segment_startpos_eye;

    // FIXME: do we need it?
    // pos_proj = projectionMatrix*vec4(startpos_eye, 1.0f);
    // pos_proj.z /= pos_proj.w;
    // FIXME: posproj.xy ???
    // pos_proj += 1.0f;
    // pos_proj /= 2.0f;

    // calculate length in texture space (needed for step width calculation)
    float segment_texture_length = 0.0;

    if (activeobjectcount > 0)  // in frag
    {

      uint ao = activeobjects;
      int aoc = activeobjectcount;

      for (int oi = 0; oi < activeobjectcount; oi++)
      {
        int objectID = findLSB(ao);
        ao &= (~(1 << objectID));

        /// FIXME: continue porting from VolyRenderer
        /// vec4 textureStartPos =
        vec4 textureStartPos = volumes[0].textureMatrix * inverse(viewMatrix) *
                               current_fragment.eyePos;
        vec4 textureEndPos = volumes[0].textureMatrix * inverse(viewMatrix) *
                             next_fragment.eyePos;

        segment_texture_length =
            max(distance(textureStartPos.xyz * textureAtlasSize,
                         textureEndPos.xyz * textureAtlasSize),
                segment_texture_length);
        // vec4 texCoord = volumes[0].textureMatrix * inverse(viewMatrix) *
        // current_fragment.eyePos;
        // float value = texture(volumeSampler, texCoord.xyz).r;
        // current_fragment.color.rgb = vec3(value);
        // current_fragment.color.rgb = vec3(texCoord.xyz);

        // vec4 transferFunction = Texture(volumes[0].textureAddress,
        // vec2(value, volumes[0].transferFunctionRow));
        // vec4 transferFunction = Texture(volumes[0].textureAddress,
        // vec2(volumes[0].transferFunctionRow, texCoord.x ));
        // current_fragment.color = transferFunction;
      }

      activeobjectcount = aoc;
      //FIXME:
      segment_texture_length =
          (segment_texture_length >= 0.0f)
              ? segment_texture_length
              : distance(segment_startpos_eye, endpos_eye) * 100.0f;

      if (activeobjectcount > 0 && segment_texture_length > 0.0f)
      {
        int sample_steps = int(segment_texture_length * STEP_FACTOR);
        clamp(sample_steps, 1, MAX_SAMPLES - 1);
        float stepFactor = 1.0 / float(sample_steps);

        // noise offset
        startpos_eye = segment_startpos_eye;  // + noise offset;

        // FIXME: check code
        // textureStartPos = textureStartPos +
        // noiseoffset*dirvec_eye*stepfactor;
        lastpos_eye = startpos_eye - dirvec_eye * stepFactor;

        // sample ray segment
        for (int step = 0; step < sample_steps; step++)
        {
          vec4 sampleColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
          vec3 lightPos = vec3(0.0f, 0.0f, 0.0f);

          uint ao = activeobjects;

          // sampling per non-isosurface object
          for (int objectIndex = 0; objectIndex < activeobjectcount;
               objectIndex++)
          {
            int objectID = findLSB(ao);
            if (objectID < 0)
              break;
            ao &= (~(1 << (objectID)));

            float squareGradientLength = 0.0f;
            vec4 currentColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
            vec4 TFColor;

            vec3 textureSamplePos =
                (volumes[0].textureMatrix * inverse(viewMatrix) *
                 vec4(startpos_eye, 1.0f)).xyz;

            getVolumeSample(objectID, textureSamplePos, density, gradient);
            squareGradientLength = dot(gradient, gradient);

            // transfer function lookup

            // TFColor = tflookup(volumes[0].textureAddress, density,
            // squareGradientLength);

            TFColor =
                Texture(volumes[0].textureAddress,
                        vec2(density, (volumes[0].transferFunctionRow + 0.5f) /
                                          transferFunctionRowCount));

            TFColor.xyz *= TFColor.w;
            // TFColor = vec4(0.0f, 0.0f, 1.0f, density*0.01);
            // lighting

            if (squareGradientLength > 0.05f)
            {
              vec3 lightDir = normalize(lightPos - startpos_eye);
              vec3 viewDir = -1.0f * normalize(startpos_eye);
              vec3 nGradient = normalize(gradient);

              // float dotNL = abs(dot(ngradient, lightDir));
              float dotNL = max(dot(nGradient, lightDir), 0.0f);
              vec3 H = normalize(lightDir + viewDir);
              // float dotNH = abs(dot(ngradient, H));
              float dotNH = max(dot(nGradient, H), 0.0f);
              float ka = 0.3;
              float kd = 0.5;
              float ks = 0.5;
