I am trying to implement instancing in my OpenGL program. I got it to work, and then decided to make my GLSL code more efficient by sending the Model-View-Projection multiplication matrix as an input to the GLSL program so that the CPU would calculate it for each instance opposite the GPU. Here is my vertex shader code (most of this question is not relevant to my question):
#version 330 core // Input vertex data, different for all executions of this shader. layout(location = 0) in vec3 vertexPosition_modelspace; layout(location = 2) in vec3 vertexColor; layout(location = 3) in vec3 vertexNormal_modelspace; layout(location = 6) in mat4 models; layout(location = 10) in mat4 modelsV; layout(location = 14) in mat4 modelsVP; // Output data ; will be interpolated for each fragment. out vec3 newColor; out vec3 Position_worldspace; out vec3 Normal_cameraspace; out vec3 EyeDirection_cameraspace; // Values that stay constant for the whole mesh. uniform mat4 MVP; uniform mat4 MV; uniform mat4 P; uniform mat4 V; uniform mat4 M; uniform int num_lights; uniform vec3 Lights[256]; void main(){ // Output position of the vertex, in clip space : MVP * position gl_Position = P * modelsV * vec4(vertexPosition_modelspace,1); // Position of the vertex, in worldspace : M * position Position_worldspace = (models * vec4(vertexPosition_modelspace,1)).xyz; // Vector that goes from the vertex to the camera, in camera space. // In camera space, the camera is at the origin (0,0,0). vec3 vertexPosition_cameraspace = ( modelsV * vec4(vertexPosition_modelspace,1)).xyz; EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace; // Normal of the the vertex, in camera space Normal_cameraspace = ( modelsV * vec4(vertexNormal_modelspace,0)).xyz; // UV of the vertex. No special space for this one. newColor = vertexColor; }
The above code works, but only because I do not use the latest VP input models to calculate gl_position. If I use it (instead of calculating P * modelsV), the instances will not be drawn, and I will get this error:
Linking program Compiling shader : GLSL/meshColor.vertexshader Compiling shader : GLSL/meshColor.fragmentshader Linking program Vertex info 0(10) : error C5102: input semantic attribute "ATTR" has too big of a numeric index (16) 0(10) : error C5102: input semantic attribute "ATTR" has too big of a numeric index (16) 0(10) : error C5041: cannot locate suitable resource to bind variable "modelsVP". Possibly large array.
I am sure that I am binding it correctly in my OpenGL code, because if I change the input models of VV to V models so that it is 10 instead of 14, I can use it, but not Model V. Is there a maximum number of inputs for the vertex shader? I really can't think of any other idea, why else would I get this error ...
I will include more of my OpenGL code, which matters here, but I'm sure it has been fixed (this is not all in one class or method):