我一直致力于在lwjgl中创建的游戏引擎中的骨架动画。我可以渲染没有动画的实体但动画实体根本不会绘制,这使得使用建议的方法here进行调试非常困难。如何在绘制任何内容时如何调试顶点着色器?
这是顶点着色器:
动画顶点着色器
#version 330 core
in vec3 position;
in vec2 textureCoordinates;
in vec3 normal;
in vec4 bones;
in vec4 weights;
out vec2 pass_textureCoordinates;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec3 toCameraVector;
uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition;
uniform mat4 joints[100];
void main(void){
vec4 originalPosition = vec4(position, 1.0);
int index = int(bones.x);
vec4 animatedPosition = (joints[index] * originalPosition) * weights.x;
vec4 animatedNormal = (joints[index] * vec4(normal, 0.0)) * weights.x;
index = int(bones.y);
animatedPosition = (joints[index] * originalPosition) * weights.y;
animatedNormal = (joints[index] * vec4(normal, 0.0)) * weights.y;
index = int(bones.z);
animatedPosition = (joints[index] * originalPosition) * weights.z;
animatedNormal = (joints[index] * vec4(position,1.0)) * weights.z;
index = int(bones.w);
animatedPosition = (joints[index] * originalPosition) * weights.w;
animatedNormal = (joints[index] * vec4(normal, 0.0)) * weights.w;
vec4 worldPosition = transformationMatrix * vec4(animatedPosition.xyz,1.0);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
pass_textureCoordinates = textureCoordinates;
surfaceNormal = (transformationMatrix * vec4(animatedNormal.x,animatedNormal.y,animatedNormal.z,0.0)).xyz;
toLightVector = lightPosition - worldPosition.xyz;
toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;
}
编辑:
因此上传关节矩阵数组时可能会出错。以防万一,这是我的loadMatrices方法:
加载矩阵
protected void loadMatrices(int location, Matrix4f matrices[]){
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(matrices.length * 16);
for(int i = 0; i < matrices.length; i++){
if(matrices[i] != null){
matrices[i].store(matrixBuffer);
}
}
matrixBuffer.flip();
GL20.glUniformMatrix4(location, false, matrixBuffer);
}
更新:
使用jozxyqk的建议,简化我的着色器以确保它正在运行。我所做的就是改变这一点:
vec4 worldPosition = transformationMatrix * vec4(animatedPosition.xyz,1.0);
对此:
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
现在它使实体完美呈现(当然不使用电枢)所以现在调试起来会容易得多。不幸的是我现在可以开始调试,但明天我会在车上很长时间,所以我会调试然后我会发布更新。非常感谢jozxyqk!
更新:
我得到了它的工作,问题是我忘了激活一些属性数组。谢谢!