使用Direct3D管道进行索引的顶点混合 [英] Indexed Vertex Blending with the Direct3D Pipeline

查看:109
本文介绍了使用Direct3D管道进行索引的顶点混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.我目前正在研究用于渲染角色动画的渲染引擎.现在,我正在进行顶点融合,以使身体部位随骨骼移动.


对于每个顶点声明,我都有一个代表第一根骨骼权重的短裤,还有2个代表该顶点受其影响的骨骼的短裤.这2条短裤也是组合变换矩阵(在世界空间中)的索引,这些变换矩阵表示世界空间中每个骨骼的变换.


从文件加载模型时,将为每个顶点运行此循环以构建将要上载到顶点缓冲区的顶点数组:

Hello. I am currently working on a rendering engine which is meant to render character animations. Right now I am working on vertex blending to make the body parts move with the bones.


For each vertex declaration, I have a short that represents the first bone''s weight, and 2 shorts representing which bones the vertex is affected by. These 2 shorts also are indexes to an array of combined transformation matrices (in world space) which represent each bone''s transformation in world space.


When the model is loaded from the file, this loop is run for each vertex to build the array of vertices that will be uploaded to the vertex buffer:

for (int i=0;i<(int)_numVertex;i++)
{
  cVertices[i].x = vertex[i].pos[0];
  cVertices[i].y = vertex[i].pos[1];
  cVertices[i].z = vertex[i].pos[2];
  cVertices[i].normal.x = vertex[i].normal[0];
  cVertices[i].normal.y = vertex[i].normal[1];
  cVertices[i].normal.z = vertex[i].normal[2];
  cVertices[i].tu = vertex[i].uv[0];
  cVertices[i].tv = vertex[i].uv[1];
  cVertices[i].su = (float)(vertex[i].normal[0]/2)+0.5;
  cVertices[i].sv = (float)(vertex[i].normal[1]/2)+0.5;
  _bone1List[i] = vertex[i].boneID[0];
  _bone2List[i] = vertex[i].boneID[1];
  _boneWeight1[i] = vertex[i].boneWeight1*0.01f;

  cVertices[i].b1 = _boneWeight1[i];

  cVertices[i].matIndices = ((_bone2List[i] & 0xFF) << 8) | (_bone1List[i] & 0xFF);
}



"b1"是骨骼重量,"matIndices"是带有矩阵调色板索引的压缩DWORD.


对于每一帧,然后调用此循环以更新包含每个骨骼的组合变换矩阵的世界变换矩阵调色板:



"b1" is the bone weight, and "matIndices" is the packed DWORD with the matrix palette indices.


For each frame, this loop is then called to update the world transformation matrices palette which contains each bone''s combined transformation matrix:

for (int i=0;i<boneController._numBones;i++)
{
dev->SetTransform(D3DTS_WORLDMATRIX(i), boneController.getBoneList()[i].getCombinedTransAdr());
}




问题是,当加载模型时,整个角色会过度拉伸并离开屏幕顶部.有谁知道为什么会这样吗?

这是我的FVF声明:




The problem is, when the model is loaded, the entire character is overly stretched and goes off the top of the screen. Does anyone know why this could be happening?

Here is my FVF declatation:

#define MDLFVF (D3DFVF_XYZB2 | D3DFVF_LASTBETA_UBYTE4 | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2)
struct MDLVERTEX
{
FLOAT x, y, z;
FLOAT b1;
DWORD matIndices;
D3DVECTOR normal;
FLOAT tu, tv;
FLOAT su, sv;
};

推荐答案

可能有许多不同的原因.首先,两个骨骼的重量太低. 4是可敬的.但这很可能不是问题.

问题可能是您的顶点着色器中的数学错误.无论如何,您都需要提供更多信息以帮助我们诊断问题.

-Debdatta Basu
There could be a host of different reasons for this. First of all, two bone weights is too low. 4 is respectable. But this is most probably not the problem.

The problem could be bad math in your vertex shader. In any case, you would need to provide more info for us ti diagnose the problem.

-Debdatta Basu


这篇关于使用Direct3D管道进行索引的顶点混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆