GLSL problem with uniform

Started by
8 comments, last by V-man 15 years, 1 month ago
hello, i am using openGL with java and the GLSL i got an crazy problem and i dont know what to do. in java i send some data to the fragment shader: int ed = gl.glGetUniformLocationARB(program, "edges"); gl.glUniform4fARB(ed, 1.0f,1.0f,1.0f,1.0f); that works... (i also do this for textures etc) in the fragment shader: uniform vec4 edges; int off=0; int ec1; sampler2D tex[10]; //an array of sampler2d that is filled one time inside the fragment shader(that work perfect) ... void main(void) { ... ... ... //and here is the problem if (edges.r==0.0) ec1 = int (0); if (edges.r==1.0) ec1 = int (1); if (edges.r==2.0) ec1 = int (2); if (edges.r==3.0) ec1 = int (3); ... //that will crash and i dont know why?!?!?! texel_av = texture2D(tex[ec1] , texCoord)*pow1; //that work texel_av = texture2D(tex[0] , texCoord)*pow1; texel_av = texture2D(tex[1] , texCoord)*pow1; texel_av = texture2D(tex[2] , texCoord)*pow1; texel_av = texture2D(tex[3] , texCoord)*pow1; i dont know what to do..why is the fragment shader blocking all my basic like attempts to build some simple integer access to an array (and work with static vars inside the fragement)
Advertisement
is it crashing or what??

If it is just saying that it cannot find the uniform it might be becouse your using 'texel_av =' rather then 'texel_av +=' which means the compiler might remove all but the last one. and then remove all unused varibles which might include the uniform.. would need more info on the error...
Why are you declaring ec1 and off outside of main? If they're not uniform, varying or attribute variables, put them inside of your main function. Maybe that's the problem.
Author Freeworld3Dhttp://www.freeworld3d.org
the problem is that i am not able to work with uniform data(int)

its simple: i got an array of sampler2d..

that array works perfect when calling tex[ec1]
and ec is static (inside or outside the main of the fragment code)

but at this moment when i try to use any data from outside
the frament shader stops the work

uniform int data1;

main...

sampler2d ( tex[data1] <- that stops the frag shader

or

test1=0;
if (data1==1) test1=1;
sampler2d ( tex[test1] <- that stops the fragment shader too


....

test1=1;
sampler2d ( tex[test1] <- that works





It seems like the sampler2D tex[10] is the problem. What is the code used to initialize the vector?
gl.glUseProgramObjectARB(program);

int ed=gl.glGetUniformLocationARB(program, "edges");
gl.glUniform4fARB(ed, 0.0f,1.0f,0.0f,1.0f);



even this simple example fails:

//copy the working sampler2D t0 to tex0
if (edges.r==0.0) tex0=t0;

edges is filled with the correct data..but the fs
stops working when i use edges in any combination
with the sampler2d (direct and nodirect)



Quote://that will crash and i dont know why?!?!?!
texel_av = texture2D(tex[ec1] , texCoord)*pow1;


It shouldn't cause a crash. Update your drivers to get the latest.
If then you still have problems, it's possible to send a bug report to the company so that they correct their driver problem.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I mean, how do you initialize this vector:

sampler2D tex[10];

How is this filled? I believed that you only could pass sampler2D as uniforms.

i now understand what you asking about:

first i was trying to get the sampler2d tex[10]
as a uniform..that was not working so
i try an unprofessional way...

i get the uniform sampler2d t0,t1,t2,t3,t4,t5...

and then i copy them to tex (tex[0]=t0;tex[1]=t1...}

and that is all working perfect with no error

the problem in a short example:

static int var1= 1
uniform int var2; //var2 gets the int=1 from main code

sampler2d [tex[var1]... is working
sampler2d [tex[var2]... is not working (yes,var2 got data)


update:

this is working!!!


"vec4 texel_av=0;\n" +


" if (edges.r==0.0) texel_av += texture2D(tex0 , texCoord)*pow1;\n" +
" if (edges.r==1.0) texel_av += texture2D(tex1 , texCoord)*pow1;\n" +
" if (edges.r==2.0) texel_av += texture2D(tex2 , texCoord)*pow1;\n" +
" if (edges.r==3.0) texel_av += texture2D(tex3 , texCoord)*pow1;\n" +

" if (edges.g==0.0) texel_av += texture2D(tex0 , texCoord)*pow4;\n" +
" if (edges.g==1.0) texel_av += texture2D(tex1 , texCoord)*pow4;\n" +
" if (edges.g==2.0) texel_av += texture2D(tex2 , texCoord)*pow4;\n" +
" if (edges.g==3.0) texel_av += texture2D(tex3 , texCoord)*pow4;\n" +

" if (edges.b==0.0) texel_av += texture2D(tex0 , texCoord)*pow2;\n" +
" if (edges.b==1.0) texel_av += texture2D(tex1 , texCoord)*pow2;\n" +
" if (edges.b==2.0) texel_av += texture2D(tex2 , texCoord)*pow2;\n" +
" if (edges.b==3.0) texel_av += texture2D(tex3 , texCoord)*pow2;\n" +

" if (edges.a==0.0) texel_av += texture2D(tex0 , texCoord)*pow3;\n" +
" if (edges.a==1.0) texel_av += texture2D(tex1 , texCoord)*pow3;\n" +
" if (edges.a==2.0) texel_av += texture2D(tex2 , texCoord)*pow3;\n" +
" if (edges.a==3.0) texel_av += texture2D(tex3 , texCoord)*pow3;\n" +


[Edited by - DerTherion on March 16, 2009 4:51:43 AM]
Quote:static int var1= 1
uniform int var2; //var2 gets the int=1 from main code

sampler2d [tex[var1]... is working
sampler2d [tex[var2]... is not working (yes,var2 got data)


That's normal. It isn't supported. But still, it should cause your system to crash. Instead, it should give a error log.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement