//
// Bumpmap car
//

void main(
	  float4 inPosition : POSITION,
	  float2 inTexCoord : TEXCOORD0,
	  float3 tangent    : TANGENT,
	  float3 normal     : NORMAL,
  
  out float4 outPosition      : POSITION,
  out float2 outTexCoord      : TEXCOORD0,
  out float3 outLightDirection: TEXCOORD1,
  out float3 outR             : TEXCOORD2,
  
  uniform float3   eyePosW,
  uniform float4x4 modelViewProj,
  uniform float4x4 modelView,
  uniform float4x4 modelMatrix
)
{
  //float3 lightDir=float3(-2052.0,1555.0,3160.0);
  float3 lightDir=float3(-1000.0,800.0,800.0);

  // Transform vertex
  outPosition = mul(modelViewProj, inPosition);
  outTexCoord = inTexCoord;

  // Create coordinate system for object-> texture space
  // Adjust to match model rotation (for dynamic objects like cars)
  tangent=mul(float3x3(modelMatrix),tangent);
  normal=mul(float3x3(modelMatrix),normal);
  
  float3 bitangent=cross(tangent,normal);
  float3x3 rotation=float3x3(tangent,bitangent,normal);

  outLightDirection=mul(rotation,lightDir);
  
  // Reflection map
  float3 positionW=mul(modelMatrix,inPosition).xyz;
  float3 N=mul((float3x3)modelMatrix,normal);
  N=normalize(N);
  // Compute incident and reflected vectors
  float3 I=positionW-eyePosW;
  outR=reflect(I,N);
}
