I want to change the number of lights I loop through, so I was hoping there was a way I could do it by just changing a uniform variable. Something like this, but I get errors. Sorry, I am new to shaders.
uniform int activeLights;
void main()
{
const int nLights = int(activeLights);
for( int i=0;i<nLights;i++ )
{
}
}
I guess my card(nv Gf5500FX) doesn’t support using a uniform variable as the iteration max in a for loop. Every shader I’ve tried using that has borked on it.
So, I thought about trying something like this…
if (i < activeLights);
{
gl_FragColor +=tColor;
}
I thought this would work because it should only add the color to the fragment if i<activeLights, but it adds the values anyway.
This is the whole of the fragment shader that I’m working with.
Can someone please explain to me why it still adds tColor to gl_FragColor? I know that there are probably some things in that code that are very non-standard, but I’m very new to this. Thank you!
Originally posted by Dr_Davenstein: Ahhh… thank you very much! I was under the assumption that every single line had to end with a semicolon.
why didn’t you type
[/b]
This is illegal. You can’t assign a non-const integer to a const int. [/b]
Well, the reason I did that, was because of this error:
(16) : error C5043: profile requires index expression to be compile-time constant
I’m actually using the TyphoonLabs Shader Designer to learn with, and some of their example shaders have indexing variables passed to the shader as uniform integers. For some reason, my card doesn’t allow this. I couldn’t find anything in the specs about it, but I gave up looking pretty quickly. I just decided to try and find a way around it.
Well, your card doesn’t support dynamic branching, so you’ll have to use static loop count. If you need to support varying number of loops you’ll have to create several instances of the shader with each number of loops you plan to use. Just passing a #define value when you compile should work.
[/b]
This is illegal. You can’t assign a non-const integer to a const int.</font><hr /></blockquote><font size=“2” face=“Verdana, Arial”>I have to say that const is somewhat confusing in GLSL. In CPP, it means that the variable is constant in the scope, but it can still have different values, every time you run it. In GLSL, it is a compile time constant. I believe that CG makes this explicit by requiring you to say static const.