 
 	out_depth    = texelFetch(depth_sampler,    ivec2(vertex_out.tex_coords * tex_size) + center_offsets[max_index], 0);
 	out_mat_data = texelFetch(mat_data_sampler, ivec2(vertex_out.tex_coords * tex_size) + center_offsets[max_index], 0);
-
-/*
-
-	float depth[4];
-	vec4  mat_data[4];
-	vec3  normal[4];
-	float score[4];
-
-	ivec2 center = ivec2(vertex_out.tex_coords*textureSize(depth_sampler, 0));
-
-	for(int i=0; i<4; i++) {
-		ivec2 p = center + offsets[i];
-
-		depth[i]    = texelFetch(depth_sampler,    p, 0).r;
-		mat_data[i] = texelFetch(mat_data_sampler, p, 0);
-		normal[i]   = decode_normal(mat_data[i].rg);
-		score[i] = 0;
-	}
-	
-	// calc score
-	for(int j=0; j<4; j++) {
-		for(int i=0; i<j; i++) {
-			score[i] += g1(vec2(offsets[j]-offsets[i]).length()) * g2(1.0 - dot(normal[j], normal[i])) * g3(depth[j] - depth[i]);
-		}
-		for(int i=j+1; i<4; i++) {
-			score[i] += g1(vec2(offsets[j]-offsets[i]).length()) * g2(1.0 - dot(normal[j], normal[i])) * g3(depth[j] - depth[i]);
-		}
-	}
-	for(int j=4; j<16; j++) {
-		ivec2 p_j = center + offsets[j];
-
-		float d = texelFetch(depth_sampler,                  p_j, 0).r;
-		vec3  n = decode_normal(texelFetch(mat_data_sampler, p_j, 0).rg);
-
-		for(int i=0; i<4; i++) {
-			score[i] += g1(vec2(offsets[j]).length()) * g2(1.0 - dot(n, normal[i])) * g3(d - depth[i]);
-		}
-	}
-
-
-	float top_score = score[0];
-	int top_index = 0;
-	for(int i=1; i<4; i++) {
-		if(score[i] > top_score) {
-			top_score = score[i];
-			top_index = i;
-		}
-	}
-
-	out_depth    = vec4(depth[top_index], 0,0,1);
-	out_mat_data = mat_data[top_index];
-*/
-//	out_depth = textureLod(depth_sampler, vertex_out.tex_coords, src_lod);
-//	out_mat_data = textureLod(mat_data_sampler, vertex_out.tex_coords, 0);
 }


	vec4 center_normals_x = vec4(normal_x_00.y, normal_x_10.x, normal_x_11.w, normal_x_01.z);

	score *= vec4(g2(avg_normal_x - center_normals_x.x),
	              g2(avg_normal_x - center_normals_x.y),
	              g2(avg_normal_x - center_normals_x.z),
	              g2(avg_normal_x - center_normals_x.w) );


	vec4 normal_y_00 = textureGather(mat_data_sampler, uv_00, 1);


	vec4 center_normals_y = vec4(normal_y_00.y, normal_y_10.x, normal_y_11.w, normal_y_01.z);

	score *= vec4(g1(avg_normal_y - center_normals_y.x),
	              g1(avg_normal_y - center_normals_y.y),
	              g1(avg_normal_y - center_normals_y.z),
	              g1(avg_normal_y - center_normals_y.w) );

	int max_index = 0;
	if(score.y > score.x)
