1

我一直在为一款流行游戏编写模型查看器并开始处理动画。骨架/动画存储在一个 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 以获得真实结果。

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

在此处输入图像描述

相反,我得到:

在此处输入图像描述

该模型是一个模仿者,看起来像

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

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

4

0 回答 0