Jump to content
  • Advertisement
Sign in to follow this  
smallfry

glsl: weird problem using integer index for array

This topic is 2536 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

I'm having a very strange problem with my fragment shader. Let me show you what's working:


// this works:
if (gl_LightSource[0].position.w >= 0.0)
att = 1.0;
if (gl_LightSource[1].position.w >= 0.0)
att = 1.0;


// so does this:
int i = 0;
if (gl_LightSource.position.w >= 0.0)
att = 1.0;
int j = 1;
if (gl_LightSource[j].position.w >= 0.0)
att = 1.0;


// no problems here either:
int i;
for (i=0; i<1; i++)
if (gl_LightSource.position.w >= 0.0)
att = 1.0;
for (i=1; i<2; i++)
if (gl_LightSource.position.w >= 0.0)
att = 1.0;


Things like this make the shader go hay-wire:


// shader goes bonkers:
int i;
for (i=0; i<2; i++)
if (gl_LightSource.position.w >= 0.0)
att = 1.0;


// shader goes bonkers with this, too:
int i = 0;
if (gl_LightSource.position.w >= 0.0)
att = 2.0;
int j = i + 1;
if (gl_LightSource[j].position.w >= 0.0)
att = 2.0;


I just can't figure it out. By the way, my shader runs totally fine on windows, but on my macbook pro, this bizarre problem cropped up. Basically, I can't ever increment i, otherwise things just go nuts. What actually gets displayed on screen is nothing like what it should, even if all the rest of the shader is is simply gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);.

I'm at the end of my rope here... is there something about the shaders I should know about?

p.s.: one final thing, I add a #version 120 at the top of the shaders, and the windows and mac shader files are identical (everything is identical, the code it totally cross-platform).

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!