[GLSL]Varrying array question and discard weird thing...

Started by
8 comments, last by _the_phantom_ 19 years ago
Hello, I was wondering if we could have varying arrays(of floats) in vertex/fragment shaders. How does the vertex shader interpolates in this case? Also, I have a program running at 5FPS whith a lot of rendering. When discarding all my fragments(just to estimate the cost of my shaders), I only have 10FPS, wich is illogical cause my fragment shaders have big loops with atan in it... Is discard something costy and should be avoided? Cheers, Jeff.
Advertisement
what card at you using?

In theory, an array of varying data, if it can be done i've never tried, each array element will be dumpped into its own interpolater per vertex
It is a GeForce 6600.

What about the discard stuff?
thats why i asked about the card.
I assume you discard without performing any other fragment operations? I dont belive its that expensive on your hardware, however I cant find out anything to confirm it.
The only other thing I can think is that when you kill the fragments you shift the bottleneck else where...
What is really weird is that when rendering my geometry I achieve between 2 and 10 frames per seconds, but when discarding in my fragment shader I always get 2 FPS. How can such a thing be possible?
Can it be a driver issue?

And for the varrying array, if my vertex shader code is something like this :
varrying float tab[100];void main (void){//Transforming the vertice in screen spacegl_Position = ftransform();//Two texture fetches depending on my transformed vertice coordinates x and yposition_1 = vec3(texture2D(texture_1, vec2(gl_Position)));position_2 = vec3(texture2D(texture_2, vec2(gl_Position)));//The texture texels R component are used herefor (i=position_1.x; i<position_2.x; i++){tab = position_1.y + position_2.y + position_1.z + position_2.z;}


In this case, will the array for each fragment be the result of the interpolated gl_Position between vertices, so that texture fetches will be the right ones?

Thansk phantom for helping me out,
Cheers, Jeff.

[Edited by - _the_phantom_ on March 31, 2005 1:48:32 PM]
Quote:Original post by funkeejeffounet
In this case, will the array for each fragment be the result of the interpolated gl_Position between vertices, so that texture fetches will be the right ones?


No. For that the texture lookups would be using the gl_Position for whichever vertex is currently being processed. To use the interpolated position at each fragment you would need to hold off on the texture lookups until the fragment program.

I don't know what could be wrong with discarding the fragments though.
Quote:Original post by funkeejeffounet
What is really weird is that when rendering my geometry I achieve between 2 and 10 frames per seconds, but when discarding in my fragment shader I always get 2 FPS. How can such a thing be possible?
Can it be a driver issue?


Hmmm that could be related to the zbuffer, if your not changing the z-coords of your fragments in the fragment shader then you could be getting a speed up due to early z-rejection, however when you dump the fragments you are processing all the fragments and not writing and z-values thus the speed up due to early z-rejection goes away
Well I don't use a zbuffer in this pass :), so I guess the bottleneck is elsewhere.

I've just added in my code a "varying vec3 tab[128]" but the driver gives me a linker error. The shaders compiles fine though, I guess it is a problem coming from my uniforms or the array but I cannot guess why.

I declared the varrying array in both my vertex shader and my fragment shader.
I declared two sampler2D as uniform in my vertex shader only.
I declared a sampler1D and a sampler3D as uniforms in my fragment shader only.

From the GLSL spec it should work cause the only errors we can get are when using unifoms sharing a same name but different types. Also, if I remember correctly, I can have up to 8 uniforms on my GF6600.

Someone has a thought on this linker error? I really hope it is not the driver(I'm currently using beta 76.41).

Cheers, Jeff.
"I've just added in my code a "varying vec3 tab[128]" but the driver gives me a linker error. The shaders compiles fine though, I guess it is a problem coming from my uniforms or the array but I cannot guess why."

You are exceeding the hardware limits and if you have software emulation turned on, it exceeds the emulators limits.
Most hw have about 16 interpolators (varyings)
There is a glGet for this. Use it!
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);
yeah, that sounds right, i've just checked on my X800XT and it supports 44 varying floats (11 vec4s)

This topic is closed to new replies.

Advertisement