float4x4 worldViewProj : WorldViewProjection;
float4x4 viewProj : ViewProjection;
float4x4 world : World;
 
// Un #if 0 the appropriate calculation block below
// The float4 arrays produce cleaner address generation code, especially in vs.1.1
// At the same time, we added support for 4x3 matrices, saving 25% of our bone constant space.
float4 bones[20*3] : Bones4x3;
//float4 bones[20*4] : Bones4x4;
//float4x4 bones[20] : World;

struct vertexInputBoned {
    float4 position				: POSITION;
    float4 boneids              : BLENDINDICES;
    float4 boneweights          : BLENDWEIGHT;
};

struct vertexInputUnboned {
    float4 position				: POSITION;
};

struct vertexOutput {
    float4 hPosition			: POSITION;
};

vertexOutput VS_Shared(float4 pos)
{
    vertexOutput OUT;

    OUT.hPosition = mul(pos, viewProj);

    return OUT;
}

vertexOutput VS_TransformBoned(vertexInputBoned IN) 
{
    float4 pos;
    float weight4;
    weight4 = 1 - dot(IN.boneweights.xyz, float3(1,1,1));
#if 0
    // bones as float4[4]
    float4 idx = IN.boneids * 1020.1;
    pos.xyz = mul(IN.position, transpose(float4x4(bones[idx.x], bones[idx.x+1], bones[idx.x+2], bones[idx.x+3]))) * IN.boneweights.x;
    pos.xyz += mul(IN.position, transpose(float4x4(bones[idx.y], bones[idx.y+1], bones[idx.y+2], bones[idx.y+3]))) * IN.boneweights.y;
    pos.xyz += mul(IN.position, transpose(float4x4(bones[idx.z], bones[idx.z+1], bones[idx.z+2], bones[idx.z+3]))) * IN.boneweights.z;
    pos.xyz += mul(IN.position, transpose(float4x4(bones[idx.w], bones[idx.w+1], bones[idx.w+2], bones[idx.w+3]))) * weight4;
#endif
#if 1
    // bones as float4[3]
    float4 idx = IN.boneids * 765.1;
    pos.xyz = mul(IN.position, transpose(float3x4(bones[idx.x], bones[idx.x+1], bones[idx.x+2]))) * IN.boneweights.x;
    pos.xyz += mul(IN.position, transpose(float3x4(bones[idx.y], bones[idx.y+1], bones[idx.y+2]))) * IN.boneweights.y;
    pos.xyz += mul(IN.position, transpose(float3x4(bones[idx.z], bones[idx.z+1], bones[idx.z+2]))) * IN.boneweights.z;
    pos.xyz += mul(IN.position, transpose(float3x4(bones[idx.w], bones[idx.w+1], bones[idx.w+2]))) * weight4;
#endif
#if 0
    // bones as mat
    float4 idx = IN.boneids * 255.1;
    pos.xyz = mul(IN.position, bones[idx.x]) * IN.boneweights.x;
    pos.xyz += mul(IN.position, bones[idx.y]) * IN.boneweights.y;
    pos.xyz += mul(IN.position, bones[idx.z]) * IN.boneweights.z;
    pos.xyz += mul(IN.position, bones[idx.w]) * weight4;
#endif
    pos.w = 1;
    
    return VS_Shared(pos);
}

vertexOutput VS_TransformUnboned(vertexInputUnboned IN) 
{
    float4 pos;

    pos = mul(IN.position, world);
    return VS_Shared(pos);
}

//-----------------------------------
float4 PS_ProjectDepthMap( vertexOutput IN): COLOR
{  
    return float4(1,1,1,1);
}

//-----------------------------------
technique boned
{
    pass p0
    {
		//ZEnable = true;
		//ZWriteEnable = false;
		//AlphaBlendEnable = true;
		//AlphaTestEnable = false;
		//SrcBlend = ONE;
		//DestBlend = ONE;

		VertexShader = compile vs_1_1 VS_TransformBoned();
		PixelShader  = compile ps_2_0 PS_ProjectDepthMap();
    }
}

technique unboned
{
    pass p0
    {
		//ZEnable = true;
		//ZWriteEnable = false;
		//AlphaBlendEnable = true;
		//AlphaTestEnable = false;
		//SrcBlend = ONE;
		//DestBlend = ONE;

		VertexShader = compile vs_1_1 VS_TransformUnboned();
		PixelShader  = compile ps_2_0 PS_ProjectDepthMap();
    }
}
