 		alpha_acc += alpha_sample;
 		vec += delta_dir;
 		length_acc += delta_dir_len;
+
+
+		vec4 ScreenCoords = vec4(vec, 1.0);
+		ScreenCoords -= vec4(0.5, 0.5, 0.5, 0.0);
+		ScreenCoords = uProjMatrix * uViewMatrix * uModelMatrix * ScreenCoords;
+
+		float Depth = ScreenCoords.z / ScreenCoords.w;
+		Depth += 1.0;
+		Depth /= 2.0;
+
+		if (Depth > CurrentDepth)
+		{
+			//if (Debug == 1)
+			{
+				//gl_FragColor = vec4(0, 0, 0, 1);
+			}
+			break;
+		}
+
 		if (length_acc >= len || alpha_acc > 1.0)
 		{
-			if (Debug == 1)
+			//if (Debug == 1)
 			{
-				gl_FragColor = vec4(1, 1, 1, 1);
-				return;
+				//gl_FragColor = vec4(1, 1, 1, 1);
 			}
 			break; // terminate if opacity > 1 or the ray is outside the volume
 		}

		FrontPosition = CameraPosition.xyz;
		if (Debug != 0)
		{
			//gl_FragColor = vec4(0, 0, 1, 1);
			//return;
		}
	}


		FrontPosition = CameraPosition.xyz;
		if (Debug != 0)
		{
			gl_FragColor = vec4(1, 0, 0, 1);
			return;
		}
	}
	else if (rayAABBIntersect(CameraPosition.xyz, (BackPosition - vec3(0.5)) - CameraPosition.xyz, vec3(-0.5), vec3(0.5)))
