uniform float3x4 	matArrayBones[60];
uniform float4x4 	matViewProjection;
uniform float4 		texelOffsets;	

static const int  BONES_PER_VERTEX = 4;

struct VS_INPUT_CASTER
{
	float4 position 	: POSITION;
	float4 blendIdx 	: BLENDINDICES;
	float4 blendWeight 	: BLENDWEIGHT;
};

struct VS_OUTPUT_CASTER
{
	float4 position : POSITION;
	float2 depth	: TEXCOORD0;
};

VS_OUTPUT_CASTER main_vs( VS_INPUT_CASTER input )
{
	VS_OUTPUT_CASTER output;
	
	// transform by indexed matrix
	float4 blendedPos = float4(0, 0, 0, 0);
	
	for (int i = 0; i < BONES_PER_VERTEX; ++i)
	{
		blendedPos += float4( mul(matArrayBones[ input.blendIdx[i] ], input.position).xyz, 1.0) * input.blendWeight[i];
	}
	
	// view / projection
	output.position = mul(matViewProjection, blendedPos);

	output.position.xy += texelOffsets.zw * output.position.w;
	
	output.depth.x = output.position.z;	
	output.depth.y = output.position.w;

	return output;
}
