Opengl 问题:将网格蒙皮到骨架

Opengl 问题:将网格蒙皮到骨架,opengl,animation,skinning,havok,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 ma

我一直在为一款流行游戏编写模型查看器,并开始处理动画。骨架/动画存储在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 ;
#版本150
高精度浮点;
均匀mat4肿瘤模型矩阵;
均匀mat4 uViewMatrix;
均匀mat4矩阵;
统一的国际标准;
均匀mat4-uBones[252];
属性向量4定位;
属性向量4异常;
属性向量4 aTexCoord;
属性vec4颜色;
属性向量4;切线;
属性权重;
属性ivec4 aBlendIndex;
可变的vec4位置;
变化的vec4异常;
变化的vec4-vTexCoord;
可变vec4颜色;
可变mat4矩阵;
可变vec3 vLightDir;
可变vec3-vEyeVec;
无效主(无效){
vec4 transformedPosition=vec4(0.0);
vec3 transformedNormal=vec3(0.0);
ivec4 curIndex=aBlendIndex;
ivec4 curWeight=能干体重;
vec4位置=位置;
对于(int i=0;i<4;i++)
{
mat4 m44=uBones[curIndex.x];
//通过骨骼i变换偏移
transformedPosition+=m44*pos*(curWeight.x/255.0);
//移动索引/权重变量,这会移动索引和
//索引的.x组件中当前骨骼的权重
//和权重变量
curIndex=curIndex.yzwx;
curWeight=curWeight.yzwx;
}
gl_位置=uProjMatrix*uViewMatrix*uModelMatrix*transformedPosition;
}

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

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

相反,我得到:

该模型是一个模拟模型,看起来像

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