I'm trying to send a model-view matrix to the vertex shader in the form of an array. I have tried three methods of doing this; an array of floats, an array of vec4-s and an array of vec3-s. The shader is shown below (the model-view matrix is named "locate").
layout (shared) uniform uView
{
float locate[12]; // <-- METHOD 1
//vec4 locate[4]; // <-- METHOD 2
//vec3 locate[4]; // <-- METHOD 3
mat4 project;
};
in vec3 aPosition;
in vec4 aColour;
out vec4 fColour;
void main()
{
gl_Position = project*vec4( // <-- METHOD 1
locate[ 0]*aPosition.x + locate[ 3]*aPosition.y + locate[ 6]*aPosition.z + locate[ 9],
locate[ 1]*aPosition.x + locate[ 4]*aPosition.y + locate[ 7]*aPosition.z + locate[10],
locate[ 2]*aPosition.x + locate[ 5]*aPosition.y + locate[ 8]*aPosition.z + locate[11],
1.0);
//gl_Position = project*vec4( // <-- METHODS 2 & 3
// locate[0].xyz*aPosition[0] +
// locate[1].xyz*aPosition[1] +
// locate[2].xyz*aPosition[2] +
// locate[3].xyz,
// 1.0);
fColour = aColour;
}
Methods 1 and 3 only send the top three rows of the matrix; 12 floats, or 4 vec3-s. The row which generates the homogeneous coordinate just has a one on the diagonal, so it can be omitted. Method 2 sends the last row, but doesn't use it.
Methods 1 and 2 work. Method 3 doesn't. I can't figure out why. I don't get any shader compile errors. It just doesn't draw anything. I am using PyOpenGL. Is there some padding issue with arrays of vec3-s that I am not aware of?
Side note... I appreciate this is a bit of a silly example when I could just send the model-view matrix as a mat4. This is a minimal 3-dimensional example of an N-dimensional shader I am trying to implement. In N-dimensions, the aPosition variable is an array of N floats, and the model-view matrix can be a (N+1)x3 matrix. I therefore want to send the model-view matrix as an array of N+1 vec3-s.