PDA

View Full Version : Uniforms not working for one shader only ?!



_blitz
04-28-2010, 09:59 AM
Hi,

I'm using 3 shader programs and it turns out that my calls to glUniform are not working but only for the first one : I get the default values in the shader (0.0 for the floats).
The program is linked, the uniforms have their locations...
I don't understand.
Thanks for your help !
B

Ilian Dinev
04-28-2010, 10:18 AM
Without code we can only guess :) .

_blitz
04-28-2010, 10:32 AM
Ok, nothing extraordinary going on :


////////////////////
// C++ code:
////////////////////
// use the program
glUseProgram();
// Send the uniforms
glUniform1f(loc, val);
// and draw
glDraw();

////////////////////
// Vertex shader
////////////////////
uniform mat4 matModelView;
uniform mat4 matProjection;
uniform float aabbLength;
uniform float lod1;
uniform float lod2;

in vec4 vPosition;

flat out int isVisiblei;
flat out ivec2 info;

void main(void)
{
isVisiblei = 1;

info = ivec2(gl_VertexID, 0);

// Transform and project !
vec4 translatedposition4f = matProjection * (matModelView * vPosition);

// Frustum-cull
if(translatedposition4f.x+aabbLength < -translatedposition4f.w)
{isVisiblei=0;return;}
if(translatedposition4f.x-aabbLength > translatedposition4f.w)
{isVisiblei=0;return;}
if(translatedposition4f.y+aabbLength < -translatedposition4f.w)
{isVisiblei=0;return;}
if(translatedposition4f.y-aabbLength > translatedposition4f.w)
{isVisiblei=0;return;}
if(translatedposition4f.z+aabbLength < -translatedposition4f.w)
{isVisiblei=0;return;}
if(translatedposition4f.z-aabbLength > translatedposition4f.w)
{isVisiblei=0;return;}

// compute lod
if(translatedposition4f.z > lod2)
{info.y = 2; return;}
if(translatedposition4f.z > lod1)
{info.y = 1; return;}
}


If I test the value of say the aabbLength variable, I get the default value 0.0... And I know the matrices are wrong also since the culling fails and I know this code works (used it before). Any ideas ?

Dark Photon
04-28-2010, 05:17 PM
You have no version specification in your vertex shader. The default is "#version 110" (GLSL 1.1). Several things you have in your shader require "#version 130" (GLSL 1.3), such as "flat" and "gl_VertexID".

Chances are your shader isn't even compiling. Are you checking for compilation errors?

If it is compiling, what OpenGL implementation are you using anyway? (vendor/version)

_blitz
04-29-2010, 04:11 AM
No it's compiling and I am specifying the version (150) aswell, just didn't put it in the code.
I am using GL context 2.1 with glew with an ati hd5770 and xubuntu 10.04. If I change the context to 3.2 it still doesn't work though. What's really strange is that the other two shader programs run fine and I use them in the same function.

_blitz
04-29-2010, 10:24 AM
Ok it was a driver issue, I downgraded back to my old version and everything's working again.

DmitryM
04-29-2010, 10:42 AM
I experienced a similar issue: in some circumstances the shader program ignored uniforms values (all of them) passed by glUniform*.

My program used gl_VertexID as well, so this might be the case. However, I have other programs that use gl_VertexID and uniforms without a problem.

My driver is Catalyst-10.3-opengl4-preview.
It's definitely an ATI issue, but I'm not able to produce a good test case to help ATI to fix it...

Alfonse Reinheart
04-29-2010, 10:43 AM
Ok it was a driver issue

How did you determine this?

_blitz
04-30-2010, 08:34 AM
Yes I had updated to the gl4 preview version aswell


Ok it was a driver issue

How did you determine this?

Well I can only guess really but my old programs didn't work anymore since the installation neither ! So changed and everything is running smooth again... (I'm back to catalyst 10.1).