将网格蒙皮到骨架的问题

时间:2015-05-07 21:29:24

标签: opengl animation skinning havok

我一直在为流行游戏编写模型查看器并开始处理动画。骨架/动画存储在Havok二进制文件中,我使用Havok引擎加载和动画。然后将动画骨骼矩阵发送到要剥皮的GLSL着色器。

这就是着色器的样子:

#version 150
precision highp float;

uniform mat4 uModelMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uProjMatrix;

uniform int uNumBones;
uniform mat4 uBones[252];

attribute vec4 aPosition;
attribute vec4 aNormal;
attribute vec4 aTexCoord;
attribute vec4 aColor;
attribute vec4 aBiTangent;

attribute ivec4 aBlendWeight;
attribute ivec4 aBlendIndex;

varying vec4 vPosition;
varying vec4 vNormal;
varying vec4 vTexCoord;
varying vec4 vColor;

varying mat4 vTBNMatrix;    
varying vec3 vLightDir;
varying vec3 vEyeVec;

void main(void) {       

vec4 transformedPosition = vec4(0.0);
vec3 transformedNormal = vec3(0.0);

ivec4 curIndex = aBlendIndex;
ivec4 curWeight = aBlendWeight;
vec4 pos = aPosition;

for (int i = 0; i < 4; i++)
{

    mat4 m44 = uBones[curIndex.x];

    // transform the offset by bone i
    transformedPosition += m44 * pos * (curWeight.x/255.0);   

    // shift over the index/weight variables, this moves the index and 
    // weight for the current bone into the .x component of the index 
    // and weight variables
    curIndex = curIndex.yzwx;
    curWeight = curWeight.yzwx;
}

gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * transformedPosition ;

}

权重以UBYTE4N DirectX格式存储,因此我将它们作为整数发送到着色器并除以255.0以获得真实结果。

奇怪的是,这是参考姿势应该是什么样的(没有应用于网格的蒙皮操作,红点只是单独的骨骼翻译):

enter image description here

相反,我得到:

enter image description here

该模型是模仿的,看起来像

http://ffxiv.consolegameswiki.com/images/thumb/e/e6/Treasure_box2.jpg/400px-Treasure_box2.jpg

这个着色器看起来是否正确?什么可能导致这个问题?

0 个答案:

没有答案