Sign in to follow this  

The limit of "for" in shader?

This topic is 4110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by rapso
instead of
Quote:
Original post by ARB1130
gl_FragColor = vec4(b,b,b,1.0);

try
[code]
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.



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!


Share this post


Link to post
Share on other sites
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! ^_^

Share this post


Link to post
Share on other sites

This topic is 4110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this