Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Passing an array of glm::mat4 to vertex shader

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2016

    Passing an array of glm::mat4 to vertex shader

    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:

    Code :
    class model{
    glm::mat4 finalBoneTransforms[10];
    void model::draw(){
    	//Set Joints
    	int jointLoc = glGetUniformLocation(shaderID, "jointTransforms");
    	glUniformMatrix4fv(jointLoc, 10 , GL_FALSE, glm::value_ptr(; 

    And my shader:

    Code :
    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!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Quote Originally Posted by Patsch View Post
    Code :
    glm::mat4 finalBoneTransforms[10];

    Code :
    	glUniformMatrix4fv(jointLoc, 10 , GL_FALSE, glm::value_ptr(;
    How does using .at() on a C-style array even compile?

    Other than that, I don't see any problem with the code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts