
#define FOG

uniform vec3 lightpos;	// fucking ATI and their stupid drivers for not letting me write good code
uniform vec3 lightpos2; // fuckings to ATI again

varying vec3 normal;
varying vec3 lightDir[2];
varying vec3 eye;
varying float camdot;

#ifdef FOG
	varying float fogFactor;
#endif

void main() {
	gl_TexCoord[0] = gl_TextureMatrix[0]*gl_MultiTexCoord0;

	vec4 tangent = vec4(gl_MultiTexCoord7);

	vec3 n = normalize(gl_NormalMatrix*gl_Normal);
	vec3 t = normalize(gl_NormalMatrix*tangent.xyz);
	vec3 b = cross(n, t)*tangent.a;

	vec4 pos = gl_ModelViewMatrix*gl_Vertex;

	camdot = 1.0-dot(n, normalize(-pos.xyz));
	//camdot = camdot*camdot*camdot*2.0;
	camdot = camdot*camdot*1.5;

	vec3 tmpVec;

//		tmpVec = vec3(gl_LightSource[i].position-pos);
		tmpVec = lightpos-pos.xyz;

		lightDir[0].x = dot(tmpVec, t);
		lightDir[0].y = dot(tmpVec, b);
		lightDir[0].z = dot(tmpVec, n);

		tmpVec = lightpos2-pos.xyz;
		lightDir[1].x = dot(tmpVec, t);
		lightDir[1].y = dot(tmpVec, b);
		lightDir[1].z = dot(tmpVec, n);


	tmpVec = -pos.xyz;
	eye.x = dot(tmpVec, t);
	eye.y = dot(tmpVec, b);
	eye.z = dot(tmpVec, n);

	normal = n;

	gl_Position = ftransform();

	#ifdef FOG
		gl_FogFragCoord = length(pos.xyz);
		fogFactor = clamp((gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale, 0.0, 1.0);
	#endif
}
