<cgvp>
<profile>arbvp1</profile>
<compilerargs>-posinv</compilerargs>
<variablemap variable="light 0 position" destination="LightPos" />
<variablemap variable="light 0 attenuation" destination="Attenuation" />
<program>
<![CDATA[

struct app2vertex {
	float4 Position : POSITION;
	float4 Normal : NORMAL;
	float4 TexCoord : TEXCOORD0;
	float3 Tangent : TEXCOORD1;
	float3 BiNormal : TEXCOORD2;
};

struct vertex2fragment { 
	float4 Position : POSITION;
	float4 TexCoord : TEXCOORD0;
	float3 oLightDir : TEXCOORD1;
	float3 oEyeVec : TEXCOORD2;
	float4 Attenuation : TEXCOORD3;
};

vertex2fragment main (app2vertex IN,
	uniform float4x4 ModelViewI : state.matrix.modelview.inverse,
	uniform float4x4 ModelViewIT : state.matrix.modelview.invtrans,
	uniform float4x4 ModelViewProj : state.matrix.mvp,
	uniform float4 LightPos,
	uniform float4 Attenuation
	)
{
	vertex2fragment OUT;
	
	float4 obLight = mul(ModelViewI, LightPos);
	float4 objLight = obLight - IN.Position;
	
	float3x3 obj2tang;
	obj2tang[0] = IN.Tangent;
	obj2tang[1] = IN.BiNormal;
	obj2tang[2] = IN.Normal;
	
	float3 tangLight = mul (obj2tang, objLight.xyz);
	float3 eyeVec = ModelViewIT[3] - IN.Position;
	float3 tangEyeVec = mul (obj2tang, eyeVec);

	float4 pos = mul (ModelViewProj, IN.Position);
	OUT.Position = pos;
	OUT.TexCoord = IN.TexCoord;
	OUT.oLightDir = tangLight;
	OUT.oEyeVec = tangEyeVec;

	OUT.Attenuation = -objLight*Attenuation.y*0.4 + 0.5;
	OUT.Attenuation.w = 0.5;


	return OUT;
}

]]>
</program>
</cgvp>
