uniform float4x4	matWorldViewProj;
uniform float4x4	matWorld;

static const float 	TILING_MODIFIER = 40.0f;
uniform float		worldSize;
uniform float		offset;
uniform float		fRotationAngle;

struct VS_INPUT 
{
	float3 position						: POSITION;
	float2 uv0							: TEXCOORD0;
};

struct VS_OUTPUT 
{
	float4 position						: POSITION;

	float2 uv0 							: TEXCOORD0;
	float2 greyAreaUV					: TEXCOORD1;
	float3 wsPos						: TEXCOORD2;
};

VS_OUTPUT main_vs( VS_INPUT input )
{
	VS_OUTPUT output;

	float4 inPosHomogeneous = float4( input.position, 1.0f );
	
	output.position =  mul( matWorldViewProj, inPosHomogeneous );
	
	output.uv0 = input.uv0;

	output.wsPos = mul( matWorld, inPosHomogeneous).xyz;

	float2 greyAreaUV = float2( (input.position.x - offset)/worldSize, (input.position.z - offset)/worldSize );
	output.greyAreaUV = greyAreaUV - float2(0.5f, 0.5f);
	
	float fAngle = fRotationAngle * 3.14f / 180.0f;
	float cf = cos(fAngle);
	float sf = sin(fAngle);

	float2x2 rotation;
	rotation._11 = cf;
	rotation._21 = -sf;
    rotation._12 = sf;
    rotation._22 = cf;

	output.greyAreaUV = mul(output.greyAreaUV, rotation);
	output.greyAreaUV += float2(0.5f, 0.5f);

	return output;
}
