varying vec2 TexCoord0;
varying vec4 ViewCoords;
varying vec3 LightDir, HalfVec, WorldNormal, WorldPos, CamDir;

uniform vec3 Eng_LocalLighting;
uniform vec3 Eng_LocalCameraPos;
uniform vec3 Eng_WorldCameraPos;

uniform mat4 Eng_ObjectMatrix;

attribute vec3 TSM0, TSM1, TSM2;

void main()
{
	TexCoord0 = gl_MultiTexCoord0.xy;
	mat3 TangentSpaceMatrix = mat3(TSM0.xyz, TSM1.xyz, TSM2.xyz);

	CamDir = TangentSpaceMatrix * normalize(Eng_LocalCameraPos-gl_Vertex.xyz);
	LightDir = TangentSpaceMatrix * Eng_LocalLighting;

	HalfVec = CamDir + LightDir;

	WorldNormal = (Eng_ObjectMatrix * vec4(TSM0.z, TSM1.z, TSM2.z, 0.0)).xyz;
	vec3 wpos = (Eng_ObjectMatrix * gl_Vertex).xyz;
	
	WorldPos = wpos;
	
	gl_Position = ftransform();
	ViewCoords = gl_Position;
}
