公告

联系我:我的126邮箱: billhsu。 Locations of visitors to this page
<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 41
  • 文章 - 0
  • 评论 - 82
  • 引用 - 0

常用链接

留言簿(16)

随笔分类

随笔档案

相册

Game Dev

搜索

  •  

最新评论

阅读排行榜

评论排行榜

基于shader的骨骼蒙皮计算
我的古董显卡很操蛋,好端端的shader,传骨骼矩阵进去,硬是没反应。。
寻寻觅觅,找到了 NVIDIA SDK 的example,终于解决了。
难道我的显卡不支持BLENDINDICES和BLENDWEIGHT?
BLENDINDICES和BLENDWEIGHTTEXCOORD[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.

= 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.

= input.Indices.z;

// Add third transformed position only
    tempPos += mul(inPos, bones[i]) * input.Weights.z;

/////////////////////////////////////////////////////////////////////
    // FOURTH BONE

= 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;
}

posted on 2010-04-01 22:10 Bill Hsu 阅读(984) 评论(0)  编辑 收藏 引用 所属分类: Game DevAlgorithm


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理