static const int MAX_MATRICES = 128;
struct VSInput
{
float3 position : POSITION0;
float2 uv : TEXCOORD;
//float2 bag : BAG;
float3 normal : NORMAL;
//float baga : BAGA;
float4 Bone_Nbr : POSITION1;
float4 Weight : POSITION2;
float4 Bone_Nbr2 : POSITION3;
float4 Weight2 : POSITION4;
//float3 tangent : TANGENT;
//float2 pack1 : TEXCOORD3;
//float3 pack2 : TEXCOORD4;
};
struct PSInput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD;
float3 normal : NORMAL;
};
cbuffer cb0 : register(b0)
{
//float4x4 g_mWorld;
//float4x4 g_mView;
//float4x4 g_mProj;
matrix bones[MAX_MATRICES] : WORLDMATRIXARRAY;
};
PSInput VSMain(VSInput input)
{
PSInput result;
float4x4 tmp;
tmp[0] = float4(1,0,0,0); tmp[1] = float4(0,1,0,0); tmp[2] = float4(0,0,1,0); tmp[3] = float4(0,0,0,1);
//float4x4 tmp = bones[26];
if (input.Bone_Nbr.x != -1) tmp = bones[input.Bone_Nbr.x+3] * input.Weight.x;
if (input.Bone_Nbr.y != -1) tmp = tmp + (bones[input.Bone_Nbr.y+3] * input.Weight.y);
if (input.Bone_Nbr.z != -1) tmp = tmp + (bones[input.Bone_Nbr.z+3] * input.Weight.z);
if (input.Bone_Nbr.w != -1) tmp = tmp + (bones[input.Bone_Nbr.w+3] * input.Weight.w);
if (input.Bone_Nbr2.x != -1) tmp = tmp + (bones[input.Bone_Nbr2.x+3] * input.Weight2.x);
if (input.Bone_Nbr2.y != -1) tmp = tmp + (bones[input.Bone_Nbr2.y+3] * input.Weight2.y);
if (input.Bone_Nbr2.z != -1) tmp = tmp + (bones[input.Bone_Nbr2.z+3] * input.Weight2.z);
if (input.Bone_Nbr2.w != -1) tmp = tmp + (bones[input.Bone_Nbr2.w+3] * input.Weight2.w);
//if (input.Bone_Nbr.x != -1) tmp = mul(tmp,bones[0]);
//else tmp = bones[0];
result.position = mul(float4(input.position, 1.0f), tmp); //g_mWorld);
result.position = mul(result.position, bones[0]);
result.position = mul(result.position, bones[1]);
result.position = mul(result.position, bones[2]);
result.uv = input.uv;
// Calculate the normal vector against the world matrix only.
result.normal = mul(input.normal, (float3x3)tmp); //bones[0]); //g_mWorld);
// Normalize the normal vector.
result.normal = normalize(result.normal);
return result;
}