我的古董显卡很操蛋,好端端的shader,传骨骼矩阵进去,硬是没反应。。
寻寻觅觅,找到了 NVIDIA SDK 的example,终于解决了。
难道我的显卡不支持
BLENDINDICES和BLENDWEIGHT?
把
BLENDINDICES和BLENDWEIGHT用TEXCOORD[n]表示才正常。。
不说废话,直接上代码。
matrix ViewProjMatrix;
float4x3 bones[70] : WORLDMATRIXARRAY;
struct VS_INPUT
{
float3 Position : POSITION;
float3 Normal : NORMAL0;
float2 TexCoord0 : TEXCOORD0;
float4 Weights:TEXCOORD1;
float4 Indices:TEXCOORD2;
};
struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Diffuse : COLOR;
float2 Tex0 : TEXCOORD0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output = (VS_OUTPUT)0;
float3 Normal = 0.0f;
float i; // Index into matrix palette
float4 inPos;
inPos.xyz = input.Position;
inPos.w = 1;
float3 tempPos, tempNormal;
/////////////////////////////////////////////////////////////////////
// FIRST BONE
// We don't worry about the ELSE condition because we defined the
// initial conditions.
// grab first bone matrix
i = input.Indices.x;
// First transformed position and normal
tempPos = mul(inPos, bones[i]) * input.Weights.x;
tempNormal = mul(input.Normal, (float3x3)bones[i]) * input.Weights.x;
/////////////////////////////////////////////////////////////////////
// SECOND BONE
// Next bone.
i = input.Indices.y;
// Add second transformed position and normal
tempPos += mul(inPos, bones[i]) * input.Weights.y;
tempNormal += mul(input.Normal, (float3x3)bones[i]) * input.Weights.y;
/////////////////////////////////////////////////////////////////////
// THIRD BONE
// Note we only skin the normal by the first two bones, these are by
// far the most significant.
i = input.Indices.z;
// Add third transformed position only
tempPos += mul(inPos, bones[i]) * input.Weights.z;
/////////////////////////////////////////////////////////////////////
// FOURTH BONE
i = input.Indices.w;
// Add fourth transformed position only
tempPos += mul(inPos, bones[i]) * input.Weights.w;
// normalize normals
Normal = normalize(tempNormal);
//OUT.Diffuse.xyz = max(dot(Normal, lhtDir), 0).xxx;
output.Diffuse.x=1;
output.Diffuse.y=1;
output.Diffuse.z=1;
// copy the input texture coordinate through
output.Tex0 = input.TexCoord0.xy;
float4 finalPos;
finalPos.xyz = tempPos;
finalPos.w = 1;
// Transform the final skinned position
output.Pos = mul(finalPos, ViewProjMatrix);
return output;
}