 	vec4 sp_world = u_InvViewProj * sp_ndc;
 	vec3 view = normalize(sp_world.xyz / sp_world.w - u_CamPos.xyz);
 
-	//vec3 pos = cast_ray_with_latitude(0.0, u_CamPos.xyz, view).xyw;
+	//vec3 pos = cast_ray_to_plane(0.0, u_CamPos.xyz, view);
+	//pos.z = get_surface(pos.xy).low_alt;
 	//Target0 = texture(t_Palette, pos.z / u_TextureScale.z);
 	vec3 pos = cast_ray_to_map(u_CamPos.xyz, view);
 	{
 		Surface suf = get_surface(pos.xy);
 		float terrain = float(suf.low_type) + 0.5;
-		float diff = textureOffset(t_Height, suf.tex_coord, ivec2(1, 0)).x - textureOffset(t_Height, suf.tex_coord, ivec2(-1, 0)).x;
+		float diff = textureOffset(t_Height, suf.tex_coord, ivec2(1, 0)).x -
+					 textureOffset(t_Height, suf.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 - pos.z / u_TextureScale.z);
-		float color_id = texture(t_Table, vec3(0.5 * tmp + 0.5, 0.75, terrain)).x;
+		float shadow_koeff = suf.is_shadowed ? 0.25 : 0.5;
+		float color_id = texture(t_Table, vec3(shadow_koeff * tmp + 0.5, 0.75, terrain)).x;
 		Target0 = texture(t_Palette, color_id);
 	}
 	vec4 target_ndc = u_ViewProj * vec4(pos, 1.0);

	tc.z = trunc(mod(tc.y, u_TextureScale.w));
	Surface suf;
	suf.tex_coord = tc;
	suf.high_alt = suf.delta = 0.0;
	uint meta = texture(t_Meta, tc).x;
	suf.low_type = get_terrain_type(meta);
	suf.high_type = 0U;
	if ((meta & c_DoubleLevelMask) != 0U) {
		if (mod(pos.x, 2.0) >= 1.0) {
			tc.x -= 1.0 / u_TextureScale.x;
			suf.high_type = suf.low_type;
			uint meta_low = texture(t_Meta, tc).x;
			suf.low_type = get_terrain_type(meta_low);
		}else {
			uint meta_high = textureOffset(t_Meta, tc, ivec2(1, 0)).x;
			suf.high_type = get_terrain_type(meta_high);
		}
		suf.low_alt = texture(t_Height, tc).x * u_TextureScale.z;
		suf.high_alt = textureOffset(t_Height, tc, ivec2(1, 0)).x * u_TextureScale.z;
	}else {
		suf.low_alt = texture(t_Height, tc).x * u_TextureScale.z;
	}
	return suf;
}


const float c_HorFactor = 0.5; //H_CORRECTION
const uint c_DoubleLevelMask = 1U<<6, c_ShadowMask = 1U<<7;
const uint c_TerrainShift = 3U, c_TerrainBits = 3U;
const uint c_DeltaShift = 0U, c_DeltaBits = 2U;
const uint c_NumBinarySteps = 8U, c_NumForwardSteps = 0U;

out vec4 Target0;
