#define IN_HLSL
#include "shdrConsts.h"

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


struct ConnectData
{
   float4 hpos            : POSITION;
   float2 texCoord        : TEXCOORD0;
   float3 normal          : TEXCOORD1;
   float4 texCoord2       : TEXCOORD2;

};

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
                  uniform float4x4 modelview       : register(VC_WORLD_PROJ),
                  uniform float3   eyePos          : register(VC_EYE_POS)
)
{
   ConnectData OUT;

   OUT.hpos = mul(modelview, IN.position);

   OUT.texCoord = IN.position.yz;


//   OUT.texCoord = float2( IN.position.x, -IN.position.y );
   OUT.texCoord *= 0.45;
//   OUT.texCoord += float2( 1.0, 1.0 );

   
   OUT.normal = IN.normal;

   float refractTexSize = 512;

   // use projection matrix for reflection / refraction texture coords
   float4x4 texGen = { 0.5,  0.0,  0.0,  0.5 + 0.5 / refractTexSize,
                       0.0, -0.5,  0.0,  0.5 + 1.0 / refractTexSize,
                       0.0,  0.0,  1.0,  0.0,
                       0.0,  0.0,  0.0,  1.0 };

   OUT.texCoord2 = mul( texGen, OUT.hpos );


   return OUT;
}
