Vertex shader doesn't recognize some uniforms

Hi all!

I’m rather new programming with GLSL but I’ve made some simple shaders successfully. My problem now is that the following shader (vertex) doesn’t recognize three of the uniform variables I use: modelview, normalMatrix and invertedCamera.

After some tries, I’ve found out that the only uniform found is that one used in the last line: gl_Position = matrix * vertex;.

I post the two shaders; vertex and fragment:

#version 330

// Attributes per vertex: position, normal and texture coordinates
in vec4 vertex;
in vec3 normal;

uniform mat4   modelviewProj;
uniform mat4   modelview;
uniform mat3   normalMatrix;
uniform mat4   invertedCamera;

// Color to fragment program
smooth out vec3 vertOutTexCoords;

void main(void) 
    // Get surface normal in eye coordinates
    vec3 eyeNormal = normalMatrix * normal;

    // Get vertex position in eye coordinates
    vec4 vertexPos = modelview * vertex;
    vec3 vertexEyePos = normalize ( / vertexPos.w);
    // Get reflected vector
    vec4 texCoords = vec4 (reflect (vertexEyePos, eyeNormal), 1.0);

    // Rotate by flipped camera
    texCoords = invertedCamera * texCoords; = normalize (;

    // Don't forget to transform the geometry!
    gl_Position = modelviewProj * vertex;

#version 330

out vec4 fragmentColor;

uniform samplerCube textureUnit0;

smooth in vec3 vertOutTexCoord;

void main(void)
    fragmentColor = texture (textureUnit0, vertOutTexCoord.stp);

Thank you!

With “doesn’t recognize” I mean that when I try to retrieve the uniform location through glGetUniformLocation, only the modelviewProj and textureUnit0 return valid values (0 and 1), but the rest return -1. All the uniforms are necessary for the shader, so I don’t understant why the compiler “deletes” them (if the problem is the compiler, which I don’t know…).

I hope this explanation sheds some light on the problem.

In the vertex shader you have “vertOutTexCoords” and in the fragment shader “vertOutTexCoord” (note the extra / missing s)

Oh! I was trying to understand so many things at a time than I missed the simplest one.

However, I thought the linker would complaint in cases like this.

Thank you very much!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.