         }
 
         #if (VOLUME_COUNT >= 1)
-            color = add_volume_sample(volume_data[0], volume_transfer_function[0], volumes[0], ray_pos, steps, alpha_total, color);
-            alpha_total = clamp(alpha_total + color.a, 0., 1.);
+            color = add_volume_sample(volume_data[0], volume_transfer_function[0], volumes[0], ray_pos, color);
             #ifdef COORDINATE
                 weighted_coordinate += color;
             #endif
         #endif
         #if (VOLUME_COUNT >= 2)
-            color = add_volume_sample(volume_data[1], volume_transfer_function[1], volumes[1], ray_pos, steps, alpha_total, color);
-            alpha_total = clamp(alpha_total + color.a, 0., 1.);
+            color = add_volume_sample(volume_data[1], volume_transfer_function[1], volumes[1], ray_pos, color);
             #ifdef COORDINATE
                 weighted_coordinate += color;
             #endif
         #endif
 
-
-        #if (VOLUME_COUNT_MAX_INT == 0)
-            // we cannot exit early if we have max intensity algo, is it maybe more efficient to do this in a separate loop?
-            if(alpha_total >= 1.)
-                break;
-        #endif
 
         #if (VOLUME_COUNT_MAX_INT >= 1)
             float value = volume_sample(volume_data_max_int[0], volumes_max_int[0], ray_pos);


    float intensity = color_sample.a;
    //float alpha_sample = intensity * sign(data_value) * sign(1.-data_value) * 100. / float(steps) * ray_length;//clamp(1.-chisq, 0., 1.) * 0.5;//1./128.* length(color_sample) * 100.;
    float alpha_sample = intensity * 100. / float(steps) * ray_length;//clamp(1.-chisq, 0., 1.) * 0.5;//1./128.* length(color_sample) * 100.;

    //float intensity = texture2D(transfer_function, vec2(data_value, 0.5)).a;
    //color_sample = texture2D(transfer_function, data_value);
    //vec4 color_sample = texture2D(colormap, vec2(sample.a, colormap_index_scaled));
    //color_sample = texture2D(volume, ray_pos.yz);
    //float alpha_sample = opacity*intensity;//1./128.* length(color_sample) * 100.;
    alpha_sample = clamp(alpha_sample * volume.opacity_scale, 0., 1.);
    color = color_in + (1.0 - alpha_total) * color_sample * alpha_sample;
    color.a = alpha_sample;
    #ifdef COORDINATE
        vec3 weighted_coordinate = ray_pos * (alpha_sample);
        float weight_coordinate = (alpha_sample);

                // #endif
            #endif
        #endif

        #if (VOLUME_COUNT_MAX_INT == 0)
            // we cannot exit early if we have max intensity algo, is it maybe more efficient to do this in a separate loop?
            if(color.a >= 1.)
                break;
        #endif

        ray_pos += ray_delta;
        ray_length_traveled += ray_length_delta;
        if(ray_length_traveled >= ray_length)
            break;

    }

    // for max int we do the transfer function looking after we found the max
