#ifdef FLAG_ENV_MAP
uniform mat4 envMatrix;
varying vec3 envReflect;
#endif

#ifdef FLAG_NORMAL_MAP
varying mat3 tbnMatrix;
#endif

#ifdef FLAG_FOG
varying float fogDist;
#endif

varying vec4 position;
varying vec3 lNormal;

void main()
{
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = ftransform();
	gl_FrontColor = gl_Color;
	gl_FrontSecondaryColor = vec4(0.0, 0.0, 0.0, 1.0);

 // Transform the normal into eye space and normalize the result.
	position = gl_ModelViewMatrix * gl_Vertex;
	vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
	lNormal = normal;

 #ifdef FLAG_NORMAL_MAP
 // Setup stuff for normal maps
	vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
	vec3 b = cross(normal, t) * gl_MultiTexCoord1.w;
	tbnMatrix = mat3(t, b, normal);
 #endif

 #ifdef FLAG_ENV_MAP
 // Environment mapping reflection vector.
	envReflect = reflect(position.xyz, normal);
	envReflect = vec3(envMatrix * vec4(envReflect, 0.0));
	envReflect = normalize(envReflect);
 #endif

 #ifdef FLAG_FOG
	fogDist = clamp((gl_Position.z - gl_Fog.start) * 0.75 * gl_Fog.scale, 0.0, 1.0);
 #endif

 #ifdef __GLSL_CG_DATA_TYPES
 // Check necessary for ATI specific behavior
	gl_ClipVertex = (gl_ModelViewMatrix * gl_Vertex);
 #endif
}