 	uint type;
 	vec3 tex_coord;
 	bool is_underground;
-	bool is_shadowed;
+	//bool is_shadowed;
 };
 
 CastPoint cast_ray_to_map(vec3 base, vec3 dir) {

	//float t = a.z > a.w + 0.1 ? (b.w - a.w - b.z + a.z) / (a.z - a.w) : 0.5;
	result.pos = b;
	result.tex_coord = suf.tex_coord;
	result.is_shadowed = suf.is_shadowed;
	return result;
}

vec4 evaluate_color(CastPoint pt) {
	float terrain = float(pt.type) + 0.5;
	float diff = textureOffset(t_Height, pt.tex_coord, ivec2(1, 0)).x -
				 textureOffset(t_Height, pt.tex_coord, ivec2(-1, 0)).x;
	float light_clr = texture(t_Table, vec3(0.5 * diff + 0.5, 0.25, terrain)).x;
	float tmp = light_clr - c_HorFactor * (1.0 - pt.pos.z / u_TextureScale.z);
	float shadow_koeff = pt.is_shadowed ? 0.25 : 0.5;
	float color_id = texture(t_Table, vec3(shadow_koeff * tmp + 0.5, 0.75, terrain)).x;
	return texture(t_Palette, color_id);
}


	vec3 view = normalize(view_base - u_CameraPos.xyz);

	CastPoint pt = cast_ray_to_map(near_plane, view);
	float lit_factor;
	if (pt.is_underground) {
		lit_factor = 0.25;
	} else {
		vec3 light_vec = normalize(u_LightPos.xyz - pt.pos * u_LightPos.w);
		vec3 a = pt.pos;
		vec3 outside = cast_ray_to_plane(u_TextureScale.z, a, light_vec);
		vec3 b = outside;
		Surface suf = cast_ray_impl(a, b, true, 4, 4);
		lit_factor = b == outside ? 1.0 : 0.5;
	}

	vec4 frag_color = evaluate_color(pt, lit_factor);

	if (pt.type == TERRAIN_WATER) {
		vec3 a = pt.pos;
		vec2 variance = mod(a.xy, c_ReflectionVariance);
