Patsch

08-21-2017, 01:05 PM

Hey everyone,

I am desperately trying to get this single line of code to work for 5 hours now, and I cant really find any helpful documentation, so here I am, hoping you guys can give me a hand :)

Basically, I want to set a uniform mat4 array. Yet only the very first entry of the array is passed to GLSL, resulting in all vertices which are not weighted to the root bone are placed at 0/0 screen coordinates instead of world space, which of course, is not the desired result. The C++ code basically looks like:

class model{

glm::mat4 finalBoneTransforms[10];

}

void model::draw(){

//Set Joints

int jointLoc = glGetUniformLocation(shaderID, "jointTransforms");

glUniformMatrix4fv(jointLoc, 10 , GL_FALSE, glm::value_ptr(finalBoneTransforms.at(0)));

}

And my shader:

const int MAX_JOINTS = 50;

const int MAX_WEIGHTS = 4;

layout (location = 0) in vec3 aPos;

layout (location = 1) in vec3 aNormals;

layout (location = 2) in vec2 aTexCoord;

layout (location = 3) in vec4 aBoneWeight;

layout (location = 4) in ivec4 aBoneIndex;

out vec2 texCoords;

uniform mat4 jointTransforms[MAX_JOINTS];

uniform mat4 model;

uniform mat4 view;

uniform mat4 projection;

void main(void) { \n

vec4 totalLocalPos = vec4(0.0);

vec4 totalNormal = vec4(0.0)

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

mat4 jointTransform = jointTransforms[aBoneIndex[i]];

vec4 posePosition = jointTransform * vec4(aPos, 1.0);

totalLocalPos += posePosition * aBoneWeight[i];

}

gl_Position = projection*view * totalLocalPos;

texCoords = aTexCoord;

}

Would be glad if someone could point out what I am doing wrong here!

I am desperately trying to get this single line of code to work for 5 hours now, and I cant really find any helpful documentation, so here I am, hoping you guys can give me a hand :)

Basically, I want to set a uniform mat4 array. Yet only the very first entry of the array is passed to GLSL, resulting in all vertices which are not weighted to the root bone are placed at 0/0 screen coordinates instead of world space, which of course, is not the desired result. The C++ code basically looks like:

class model{

glm::mat4 finalBoneTransforms[10];

}

void model::draw(){

//Set Joints

int jointLoc = glGetUniformLocation(shaderID, "jointTransforms");

glUniformMatrix4fv(jointLoc, 10 , GL_FALSE, glm::value_ptr(finalBoneTransforms.at(0)));

}

And my shader:

const int MAX_JOINTS = 50;

const int MAX_WEIGHTS = 4;

layout (location = 0) in vec3 aPos;

layout (location = 1) in vec3 aNormals;

layout (location = 2) in vec2 aTexCoord;

layout (location = 3) in vec4 aBoneWeight;

layout (location = 4) in ivec4 aBoneIndex;

out vec2 texCoords;

uniform mat4 jointTransforms[MAX_JOINTS];

uniform mat4 model;

uniform mat4 view;

uniform mat4 projection;

void main(void) { \n

vec4 totalLocalPos = vec4(0.0);

vec4 totalNormal = vec4(0.0)

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

mat4 jointTransform = jointTransforms[aBoneIndex[i]];

vec4 posePosition = jointTransform * vec4(aPos, 1.0);

totalLocalPos += posePosition * aBoneWeight[i];

}

gl_Position = projection*view * totalLocalPos;

texCoords = aTexCoord;

}

Would be glad if someone could point out what I am doing wrong here!