I have a frament shader in GLSL language and when I use getUniformLocation with a variable then the function returns -1.
In fragment shader:
uniform sampler2DShadow shadowVar;
In C code:
idVariable = getUniformLocation(shader, "shadowVar");
idVariable is asigned -1.
I get this problem with ATI HD 5670 cards only.
Can anyone help me,please?
First, thank you for your answer. But I've found the problem.
You was right. The problem was that the variable was desactived. However, the main problem was I have used sample2DShadow function. I think HD 5600 serie ATI doesn´t implement the sample2DShadow because this function is deprecated. Now, I´m using textureProj and I don´t have any problem.
I don´t know why the GPU compiler doesn´t show any warning about the deprecated functions. Then, I could know where the problem is.
Thank you, for your interesting.
Do you mean there is a problem when you use shadow2DProj, but it works when you use textureProj with the sampler type - sampler2DShadow? The GPU compiler supports both functions for compatibility. Could you please show me where the problem is by pasting out your shader?
I explain me better. If I have a uniform variable as this:
uniform sampler2D shadow;
and I use this varible using shadow2dProj, then getUniformLocation(shader, "shadow") function will return -1. But If I use textureProj then getUniformLocation function will return a correct id value.
I don´t know if this is an error ati drivers or if ati drivers don´t implement shadow2dProj. I've tried this problem with ATI RADEON HD 5670.
I hope my explication is better
It seems impossible. It's wrong to get the uniform location from the shader object by getUniformLocation(shader, "shadow"). We'd better get it by getUniformLocation(program, "shadow"). Is it a possible root cause? Anyway, we will verify it first. I appreciate that you tell me which catalyst driver you are using now.
I can't reproduce the problem on HD5670 for the following two cases.
uniform sampler2DShadow shadow;
uniform vec4 coord;
gl_FragColor = shadow2DProj(shadow, coord);
gl_FragColor = textureProj(shadow, coord).xxxx;
Please note that shadow2DProj returns vec4 while textureProj returns float.
I have the catalyst last version. Well, I have the call function into a function. This is exactly my function:
in sampler2DShadow shadowMap,
in vec4 shadowCoord,
in float dx, int float dy,
in float ratioToPixelX, in float ratioToPixelY)
posSample = shadowCoord +
vec4(dx * ratioPixelX * shadowCoord.w,
dy * rationPixelY * shadowCoord.w,
//if (textureProj(shadowMap, posSample) != 1) // Is ok,
if (shadow2DProj(shadowMap, posSample).w != 1.) //Is bad.
shadowFactor = 1.;
shadowFactor = 0.;
If you want, you will be able to put all your code and so I could probe your version in my computer. So We could know if your program run ok in my computer.
It depends on the depth texture setting. The depth texture mode is set to GL_LUMINANCE by default, according to the GL spec, the texel value is (Lt, Lt, Lt, 1) for GL_LUMINANCE, Lt is the comparison result.
In your case, the value of shadow2DProj(shadowMap, posSample).w is always 1 if you don't specify the depth texture mode. As a result, shadowMap is optimized out by the compiler, so you can't get the valid uniform location.
I think you could get what you want by modifying the shader.