// __multiversion__
// This signals the loading code to prepend either #version 100 or #version 300 es as apropriate.

#include "shaders/fragmentVersionCentroid.h"
#include "shaders/uniformShaderConstants.h"

LAYOUT_BINDING(0) uniform sampler2D TEXTURE_0;

#if __VERSION__ >= 300
_centroid varying vec4 uv;
#else
varying vec4 uv;
#endif

#ifdef ENABLE_FOG
varying vec4 fogColor;
#endif

#ifdef ENABLE_LIGHT
varying vec4 light;
#endif

#ifndef DISABLE_TINTING
varying vec4 color;
#endif

void main()
{
	vec4 diffuse = texture2D(TEXTURE_0, uv.xy);
	vec4 base = texture2D(TEXTURE_0, uv.zw);

#ifndef DISABLE_TINTING
	base.a = mix(diffuse.r * diffuse.a, diffuse.a, color.a);
	base.rgb *= color.rgb;
#endif

#ifdef ENABLE_LIGHT
	base.rgb *= light.rgb;
#endif

#ifdef ENABLE_FOG
	//apply fog
	base.rgb = mix( base.rgb, fogColor.rgb, fogColor.a );
#endif

#ifdef UI_ENTITY
	base.a *= HUD_OPACITY;
#endif
	gl_FragColor = base;
}