//*****************************************************************************
   // Deferred shading MRT Shader
//*****************************************************************************
#define IN_HLSL
#include "../shdrConsts.h"

//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct VertData
{
   float3 normal          : NORMAL;
   float4 position        : POSITION;
   float2 texCoord        : TEXCOORD0;
   float2 lmCoord         : TEXCOORD1;
   float3 T               : TEXCOORD2;
   float3 B               : TEXCOORD3;
};


struct ConnectData
{
   float4 hpos             : POSITION;
   float2 texCoord         : TEXCOORD0;
   float3 tanToView0       : TEXCOORD1;
   float3 tanToView1       : TEXCOORD2;
   float3 tanToView2       : TEXCOORD3;
   float3 lightVec         : TEXCOORD4;
};


//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
                  uniform float4x4 modelview       : register(VC_WORLD_PROJ),
                  uniform float4x4 viewMat         : register(VC_VIEW),
                  uniform float3   inLightVec      : register(VC_LIGHT_DIR1)
)
{
   ConnectData OUT;
   OUT.hpos = mul(modelview, IN.position);

   OUT.texCoord = IN.texCoord;

   float3x3 objToTangentSpace;
   objToTangentSpace[0] = IN.T;
   objToTangentSpace[1] = IN.B;
   objToTangentSpace[2] = IN.normal;

   OUT.lightVec = mul( objToTangentSpace, -inLightVec );

   float3x3 testMat = transpose( objToTangentSpace );
   float3x3 tanToView = mul( viewMat, testMat );

   OUT.tanToView0 = tanToView[0];
   OUT.tanToView1 = tanToView[1];
   OUT.tanToView2 = tanToView[2];


   return OUT;
}
