I try to implement normal mapping into my vertex (later in my fragment shader, too). I added attributes for the needed tangents and bitangents (aNormalTangent, aNormalBiTangent), a maximum of 10 lights (uLightPos[10]) as uniform and an int uniform to globally disable/enable the use of normal mapping.
When I compile the shader program, I get no error. But if I try to find out the corresponding handle [with GL.GetAttribLocation(currentProgram, "aNormalTangent")], I always get -1 for the attributes aNormalTagent and aNormalBiTangent. Every other attribute location and every other uniform works.
Where is the error in my code? I tried commenting out parts, but I did not find the source of the error...
Here is my vertex shader code:
#version 330 in vec3 aPosition; in vec3 aColor; in vec2 aTexture; in vec3 aNormal; in vec3 aNormalTangent; in vec3 aNormalBiTangent; out vec4 vPosition; out vec4 vColor; out vec2 vTexture; out vec3 vNormal; // for shadows: out vec2 vTexCoordinate; out vec4 vShadowCoord; // for normal mapping: out vec3 vLightPosTanSpace[10]; uniform mat4 uMVP; uniform mat4 uM; uniform mat4 uMV; uniform mat4 uNormalMatrix; uniform mat4 uShadowMVP; uniform int uUseNormalMap; uniform vec4 uLightPos[10]; void main() { vShadowCoord = vec4(uShadowMVP * vec4(aPosition, 1.0)); vPosition = uM * vec4(aPosition, 1.0); vColor = vec4(aColor, 1.0); vTexture = aTexture; vNormal = normalize(vec3(uNormalMatrix * vec4(aNormal, 0.0))); // Normal mapping calculations: if(uUseNormalMap > 0) { mat3 mv3x3 = mat3(uMV[0].xyz, uMV[1].xyz, uMV[2].xyz); vec3 vertexNormal_cameraspace = mv3x3 * normalize(aNormal); vec3 vertexTangent_cameraspace = mv3x3 * normalize(aNormalTangent); vec3 vertexBitangent_cameraspace = mv3x3 * normalize(aNormalBiTangent); mat3 TBN = transpose(mat3(vertexTangent_cameraspace, vertexBitangent_cameraspace, vertexNormal_cameraspace)); vLightPosTanSpace[0] = TBN * vec3(uLightPos[0]); // --- 9 other array slots filled with vec3(0,0,0) for testing --- } else { vLightPosTanSpace = vec3[10]( vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0) ); } gl_Position = uMVP * vec4(aPosition, 1.0); }
glGetAttribLocationis usually an indication that the variable is not used by (i.e. does not affect the output of) the program and has been elided.