Gabba123XXL

08-28-2011, 01:22 PM

Hello guys,

I am working right now with GLSL and trying to get the location of some uniform variables. So far I found out that the glsl compiler makes some optimizations to these variables if they are not in use, i.e. it results in -1 location.

In my case I cannot understand it really because all variables have influence in the result.

#version 140

uniform vec3 lightPosition;

uniform vec3 skyColor;

uniform vec3 groundColor;

uniform mat4 mvMatrix;

uniform mat4 mvpMatrix;

uniform mat3 normalMatrix;

in vec3 in_position;

in vec3 in_normal;

out vec3 ex_color;

void main(void)

{

vec3 ecPosition = vec3(mvMatrix * vec4(in_position, 1.0));

vec3 tnorm = normalize(normalMatrix * in_normal);

vec3 lightVec = normalize(lightPosition - ecPosition);

float costheta = dot(tnorm, lightVec);

float a = costheta * 0.5 + 0.5;

ex_color = mix(groundColor, skyColor, a);

gl_Position = mvpMatrix * vec4(in_position, 1.0);

}

This code I have taken from the orange book. The variable "mvpMatrix" has a positive location, all others no. I hope somebody can explain me, where the problem is.

I am working right now with GLSL and trying to get the location of some uniform variables. So far I found out that the glsl compiler makes some optimizations to these variables if they are not in use, i.e. it results in -1 location.

In my case I cannot understand it really because all variables have influence in the result.

#version 140

uniform vec3 lightPosition;

uniform vec3 skyColor;

uniform vec3 groundColor;

uniform mat4 mvMatrix;

uniform mat4 mvpMatrix;

uniform mat3 normalMatrix;

in vec3 in_position;

in vec3 in_normal;

out vec3 ex_color;

void main(void)

{

vec3 ecPosition = vec3(mvMatrix * vec4(in_position, 1.0));

vec3 tnorm = normalize(normalMatrix * in_normal);

vec3 lightVec = normalize(lightPosition - ecPosition);

float costheta = dot(tnorm, lightVec);

float a = costheta * 0.5 + 0.5;

ex_color = mix(groundColor, skyColor, a);

gl_Position = mvpMatrix * vec4(in_position, 1.0);

}

This code I have taken from the orange book. The variable "mvpMatrix" has a positive location, all others no. I hope somebody can explain me, where the problem is.