Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Uniform Location = -1 even though Uniform is Active


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 19 June 2013 - 03:40 PM

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?

 

 

 

</span>

#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);
}

<span  style="color:rgb(40,40,40);font-family:arial, helvetica;font-size:14.399999618530273px">

Edited by stefthedrummer, 19 June 2013 - 03:54 PM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8138

Like
3Likes
Like

Posted 19 June 2013 - 05:20 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 20 June 2013 - 02:19 AM

thx dude.

 

Typical case of: "read first, then ask" sleep.png 



#4 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 22 June 2013 - 07:51 PM

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



#5 Koehler   Members   -  Reputation: 228

Like
0Likes
Like

Posted 26 June 2013 - 10:56 AM

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. 



#6 Ameise   Members   -  Reputation: 752

Like
2Likes
Like

Posted 19 July 2013 - 02:35 PM

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

 

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


#7 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 19 July 2013 - 02:53 PM

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?



#8 Brother Bob   Moderators   -  Reputation: 8430

Like
0Likes
Like

Posted 19 July 2013 - 03:03 PM

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.



#9 Ameise   Members   -  Reputation: 752

Like
1Likes
Like

Posted 19 July 2013 - 03:21 PM

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.



#10 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 19 July 2013 - 03:33 PM

 

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS