With GLSL, I'd be performing lighting calculations, texturing and all sorts; but does it make any difference which shader it is done in? For example, is there a performance benefit in performing lighting calculations in the vertex shader rather than the fragment shader? I'd have to pass only the end-result to the fragment shader and have it added to the fragment color. Can the same be so vice-versa?
My next question is, with regards to vertex attributes and uniforms:
Are vertex attributes global to all shaders in any shader program? For example, suppose we have:
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vertices), (GLvoid*)0);
If I then declare in the vertex shader:
layout (location = 0) in vec3 VertexPosition;
Can I also do the same in the fragment shader? Can I also do the same in a vertex shader pertaining to a second shader program?
With regards to uniforms, is it possible for me to use uniforms in all the shaders of that shader program so long as I declare them?.
uniform mat4 modelMatrix; // In the vertex shader
uniform mat4 modelMatrix; // In the fragment shader
My last question is, should all vertex attributes be consistent throughout the main program? As in, if I allocate vertex attribute 0 as VertexPosition, then I can no longer allocate that attribute to something else such as VertexNormal, correct? That could only happen unless I disable the vertex attribute array with:
glDisableVertexAttribArray(0);