The limit of "for" in shader?

Started by
5 comments, last by ARB1130 17 years, 7 months ago
Hi all: I try to do computation in shader. First, I do a FBO object and attatch 4 color + 1 depth texture my sizes are 725 x 401 Second, I do a simple loop in fragment . int b =0; for(int i = 0 ; i<n ;i++) b++; gl_FragColor = vec4(b,b,b,1.0); if n is 280 , I got 24 n is 270 14 n is 260 4 n 250 250 is right! Everyone konw what's wrong with me? Please tell me some tips or relative site. Thank you very much!
Advertisement
Where are you taking the output value from?
It obviously clamps the value to 256 and wraps up back again, 280-256=24,270-256=14 etc..
Either way, unless you're using floating point target, you shouldn't be storing that big numbers!

ch.
instead of
Quote:Original post by ARB1130
gl_FragColor = vec4(b,b,b,1.0);

try

gl_FragColor = frac(vec4(b,b,b,1.0)*vec4(1,256,65536,1));


Quote:Original post by rapso
instead of
Quote:Original post by ARB1130
gl_FragColor = vec4(b,b,b,1.0);

try

gl_FragColor = frac(vec4(b,b,b,1.0)*vec4(1,256,65536,1));



Thanks your responds!

Your approach is packing a float into a texture.

I got 0 ^_^"

And I got the values by glReadPixels.



Quote:Original post by christian h
Where are you taking the output value from?
It obviously clamps the value to 256 and wraps up back again, 280-256=24,270-256=14 etc..
Either way, unless you're using floating point target, you shouldn't be storing that big numbers!

ch.


Thanks to your idea! ^_^ 256

Yes, I use the GL_RGBA32F_ARB and GL_TEXTURE_RECTANGLE_NV

Quote:Original post by ARB1130
Hi all:

I try to do computation in shader.

First, I do a FBO object and attatch 4 color + 1 depth texture

my sizes are 725 x 401

Second, I do a simple loop in fragment .

int b =0;

for(int i = 0 ; i<n ;i++)
b++;

gl_FragColor = vec4(b,b,b,1.0);


if n is 280 , I got 24

n is 270 14

n is 260 4

n 250 250 is right!

Everyone konw what's wrong with me?

Please tell me some tips or relative site.

Thank you very much!




I found a interesting phenomenon.

I used 2 "for loop" and I can get the right value.

ex:

int b =0;
for(int i =0;i<20;i++)
for(int j =0;j<20;j++)
b++;

I still got the values by glReadPixels ->4e+002.

But the loop became bigger and bigger.

Something wrong!

EX:

250*250

I got 6.25e+004 and it is right!

251*251 is 2.173e+004

252*252 2.173e+004

252*252 2.173e+004

I don't know whats happened.

Please tell me ! Thanks!


Quote:Original post by ARB1130
Hi all:

I try to do computation in shader.

First, I do a FBO object and attatch 4 color + 1 depth texture

my sizes are 725 x 401

Second, I do a simple loop in fragment .

int b =0;

for(int i = 0 ; i<n ;i++)
b++;

gl_FragColor = vec4(b,b,b,1.0);


if n is 280 , I got 24

n is 270 14

n is 260 4

n 250 250 is right!

Everyone konw what's wrong with me?

Please tell me some tips or relative site.

Thank you very much!



I found a strange problem!

In one "for loop",the max value is 256

In two "for loop",the max value >256

Does somebody know the problem?

Thanks to responds! ^_^

This topic is closed to new replies.

Advertisement