#define IN_HLSL
#include "../shdrConsts.h"


//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct VertData
{
   float2 texCoord        : TEXCOORD0;
   float2 lmTexCoord      : TEXCOORD1;
   float3 normal          : NORMAL;
   float4 position        : POSITION;
};


struct ConnectData
{
   float4 hpos            : POSITION;
   float2 outTexCoord     : TEXCOORD0;
   float3 outNormal       : TEXCOORD1;
   float3 pos             : TEXCOORD2;
   float3 outEyePos       : TEXCOORD3;
   float4 outLightVec     : TEXCOORD4;
   float3 viewNormal      : TEXCOORD5;  // normal in view space
   float2 detailTexCoord  : TEXCOORD6;
   float2 lightmapTexCoord : TEXCOORD7;
};


//-----------------------------------------------------------------------------
// 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),
                  uniform float3   eyePos          : register(VC_EYE_POS)
)
{
   ConnectData OUT;

   OUT.hpos = mul(modelview, IN.position);
   OUT.outTexCoord = IN.texCoord;
   OUT.lightmapTexCoord = IN.lmTexCoord;

   OUT.outNormal = IN.normal;
   OUT.pos = IN.position.xyz;
   OUT.outEyePos.xyz = eyePos.xyz;
   OUT.outLightVec.xyz = -inLightVec;
   OUT.outLightVec.w = step( 0.0, dot( -inLightVec, IN.normal ) );

   float3 tempNorm = mul( viewMat, IN.normal );         // put normal in view space
   OUT.viewNormal.xyz = tempNorm * 0.5f + 0.5f;

   OUT.detailTexCoord = float2( IN.position.x / 8.0, IN.position.y / 8.0 );

   return OUT;

}
