 #endif
 
 
-    for(int i = 0; i < steps; i++) {
+    for(int i = 0; i < MAX_STEPS; i++) {
         geometry_depth = texture2D(geometry_depth_tex, pixel); 
         voxel_view_space_coord = projectionMatrix * modelViewMatrix * vec4(ray_pos+vec3(-0.5, -0.5, -0.5),1.0);
         voxel_frag_depth = ((voxel_view_space_coord.z / voxel_view_space_coord.w)+1.0)/2.0;

    return data_value;
}

vec4 add_volume_sample(sampler2D volume_data, sampler2D volume_transfer_function, Volume volume, vec3 ray_pos, int steps, float alpha_total, vec4 color_in) {
    vec4 color;
    vec3 pos_relative = (ray_pos+volume.offset)*volume.scale;
    if(any(lessThan(pos_relative, vec3(0.))) || any(greaterThan(pos_relative, vec3(1.))))


    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);//clamp(1.-chisq, 0., 1.) * 0.5;//1./128.* length(color_sample) * 100.;
    alpha_sample = clamp(alpha_sample * volume.opacity_scale, 0., 1.);

    //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.;
    float alpha_total = color_in.a + alpha_sample;
    color.rgb = color_in.rgb + (1.0 - alpha_total) * color_sample.rgb * alpha_sample;
    color.a = alpha_total;
    #ifdef COORDINATE
        vec3 weighted_coordinate = ray_pos * (alpha_sample);
        float weight_coordinate = (alpha_sample);
