#ifdef VERTEX_SHADER
	attribute vec4 Position;
	attribute vec3 Normal;
	attribute vec4 Color;
	attribute vec2 TexCoord0;

	uniform lowp mat4 ModelViewProjectionMatrix;
	uniform lowp mat4 ModelViewMatrix;
	uniform lowp vec4 CameraDirection;
	uniform lowp vec4 LightDirection;
	uniform lowp vec4 LightAmbient;
	uniform lowp vec4 LightDiffuse;

	varying lowp vec4 _Color;
	varying lowp vec4 _Light;
	varying lowp vec2 _TexCoord0;
	varying lowp float _RimLight;

	void vs_main()
	{
		vec3 _Normal = vs_skin(vec4(Normal, 0)).xyz;
		
		gl_Position = ModelViewProjectionMatrix * vs_skin(Position);
		
		_TexCoord0 = TexCoord0;
		_Color = Color;
		_Light = (LightAmbient + LightDiffuse * max(0.0, dot(LightDirection.xyz, -_Normal)));
		_RimLight = dot(CameraDirection.xyz, -_Normal);
	}
#else
	uniform sampler2D Texture0;

	uniform lowp vec4 OverlayColor;
	uniform lowp vec4 TeamColor;
	uniform lowp vec4 SurfaceColor;

	varying lowp vec4 _Color;
	varying lowp vec4 _Light;
	varying lowp vec2 _TexCoord0;
	varying lowp float _RimLight;

	void ps_main()
	{
		lowp float r = 1.0 - _RimLight;
		lowp vec4 c 	= texture2D(Texture0, _TexCoord0);
		c.rgb 	= c.rgb * c.a + TeamColor.rgb * (1.0 - c.a);
		c.rgb 	= c.rgb * _Light.rgb * (0.9 + r * 0.5);
		c.rgb 	= c.rgb * (1.0 - OverlayColor.a) + OverlayColor.rgb * OverlayColor.a;
		c.rgb	= c.rgb * SurfaceColor.rgb;
		c.a 	= SurfaceColor.a;
		
		gl_FragColor = c * _Color;
	}
#endif