shader_type spatial;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform sampler2D world_color_texture : hint_default_black, repeat_disable;

void vertex() {
	// Called for every vertex the material is visible on.
}

void fragment() {
  vec4 projected_coords = INV_VIEW_MATRIX * vec4(VERTEX, 1.0);
	
  vec4 currentColor = textureLod(screen_texture, SCREEN_UV, 0.0);
  vec4 playerColorationColor = textureLod(world_color_texture, projected_coords.xz * 0.01 + vec2(0.5), 0.0);
  vec3 colorToLuminance = vec3(0.2126, 0.7152, 0.0722);

  vec3 desaturatedColor = vec3(dot(currentColor.rgb, colorToLuminance) * 0.4) + 0.1 * currentColor.rgb;

  ALBEDO = desaturatedColor * (1.0 - playerColorationColor.a) + currentColor.rgb * playerColorationColor.a;
}

//void light() {
	// Called for every pixel for every light affecting the material.
	// Uncomment to replace the default light processing function with this one.
//}
