• Advertisement
Sign in to follow this  

Uniform Location = -1 even though Uniform is Active

This topic is 1648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone,

 

since I updated my Catalyst Driver for my 6950, my code sopped working.

The following code works fine on several machines with both NVidia and AMD Graphics, but not on my main machine.

My compiler returns uniform location -1 for "worldTexture" and "shadowMap" even though these variables are used to calculate the result!

Is it a bug, or did I miss something?

 

 

 

[source lang="cpp"]

#version 330 core
 
in  vec2 passCoord;
 
out vec3 outDiffuse;
 
uniform sampler2D diffuseTexture;
uniform sampler2D worldTexture;
uniform sampler2D normalTexture;
uniform sampler2D shadowMap;
 
layout(std140) uniform Sun {
    vec3 sunPosition;
    vec3 sunDirection;
    vec3 sunDiffuse;
};
 
layout(std140) uniform Camera {
    mat4 camViewProj;
    mat4 sunViewProj;
    mat4 sunViewCoordProj;
};
 
void main()
{
    vec3 diffuse   = texture2D(diffuseTexture, passCoord).rgb;
    vec3 normal    = texture2D(normalTexture, passCoord).rgb;
    vec3 worldPos  = texture2D(worldTexture, passCoord).rgb;
 
    float intensity         = diffuse.x + diffuse.y + diffuse.z;
 
    vec4 sunSpacePos        = sunViewCoordProj * vec4(worldPos, 1.0f);
    vec2 shadowMapCoord     = vec2(sunSpacePos);
    float curSunSpaceDepth  = texture2D(shadowMap, shadowMapCoord).x;
    float sunSpaceDepth     = sunSpacePos.z - 0.0001f;
    float shadowFactor      = (curSunSpaceDepth < sunSpaceDepth) ? 1.0f : 1.0f;
 
    outDiffuse = (diffuse * shadowFactor + intensity * sunDiffuse) * max(dot(normal, sunDirection), 0.0f);
}
[/source]
Edited by stefthedrummer

Share this post


Link to post
Share on other sites
Advertisement

See http://stackoverflow.com/questions/12307278/texture-vs-texture2d-in-glsl - texture2D is deprecated as of GL3.3, and you're using #version 330 core - in other words, if it worked before, it worked by accident (or by non-conformance) and even if some of them continue to work now, it's still by accident (or non-conformance), but you shouldn't expect it to work.

Share this post


Link to post
Share on other sites

I don't think that would effect the fact they the uniform location returns as -1. I've experienced this glitch before and I do think it's a glitch because there are some gotchas like this that crash on some systems but run fine on others. Unfortunately I can't exactly remember what fixed it, but it might possibly be your [vertex,normal,texture] client states - such as having one enabled you shouldn't or something... So you might want to check that. Also assure you're passing the right program to glGetUniformLocation

Share this post


Link to post
Share on other sites

I don't think that would effect the fact they the uniform location returns as -1....

 

Since texture2D was deprecated some time ago, it's entirely possible that the latest drivers compile it to a no-op and it always returns some constant value. This means that the sampler uniforms could indeed be optimized out, since they do not affect the output of the program. 

Share this post


Link to post
Share on other sites

Outside of that, I'd suggest the issue has to do with this line:

 

float shadowFactor      = (curSunSpaceDepth < sunSpaceDepth) ? 1.0f : 1.0f;

Share this post


Link to post
Share on other sites

I'm using a 3.3 core context and texture2D without issues. How is that possible if it is depreciated, and more importantly, what is the alternative?

Share this post


Link to post
Share on other sites

I'm using a 3.3 core context and texture2D without issues. How is that possible if it is depreciated, and more importantly, what is the alternative?

Both your questions was answered by mhagain in the very first reply.

Share this post


Link to post
Share on other sites

I'd point out again that it is likely this line:

 

float shadowFactor      = (curSunSpaceDepth < sunSpaceDepth) ? 1.0f : 1.0f;

Since both sides of the ternary are 1.0f, the compiler is likely compiling away the conditional, and since those are the only places that those variables are referenced, it is recursively compiling out those two uniforms. Most likely, if he changes one of the 1.0f's to 0.0f, he will stop getting -1.

Not to say he shouldn't correct his code otherwise, but that's probably not why this is happening.

Share this post


Link to post
Share on other sites

 

I'm using a 3.3 core context and texture2D without issues. How is that possible if it is depreciated, and more importantly, what is the alternative?

Both your questions was answered by mhagain in the very first reply.

 

Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement