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

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


struct ConnectData
{
   float4 hpos            : POSITION;
   float4 shading         : COLOR;
   float2 outTexCoord     : TEXCOORD0;
   float3 viewNormal      : TEXCOORD1;  // normal in view space
};


//-----------------------------------------------------------------------------
// 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.shading = saturate( dot(-inLightVec, IN.normal) );
   OUT.shading += 0.30 * saturate( dot(-reflect(-inLightVec, float3(0.0, 0.0, 1.0)), IN.normal) );
   OUT.shading.w = 1.0;
   OUT.outTexCoord = IN.texCoord;

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

   return OUT;
}
