Question about Loops in GLSL

Hi! I haven’t done shaders in a few years, so i was wondering if much has changed. Basically, my question is about variable loops inside them.

I have a few common cases where i would like to have variable loops inside the shaders, passed as uniforms:
First case is skinning, where I need to pass N extra arrays containing weights per vertex (and the N matrices associated with them). Back then I remember i would need to have 8 separate shaders for each weight count amount (one for vertices with 1 weight, another for vertices with 2 weights, etc).

The second case is processing lights per fragment, where I want to see the opengl lights, which ones are enabled and do the proper processing in there (so i can implement normalmaps, phong, wathever).

Well, thanks in advance!

Sorry, the question is not clear. You can use a uniform to limit the number of iterations (at least on the lastest hardware (GLSL)).

Well my question is about, how do i know what can i do, on what hardware, etc? I know the language allows me to use uniforms for the number of iterations, however I don’t really know what is supported on each card, what isnt, what the speed penalties are.

In the end, the point is how can I avoid having several shader programs for every different combination of render parameters, number of skin bones, etc. I don’t find info about that anywhere… about when using loops, conditionals, etc.

There isn’t a way to query.
Either it won’t compile, won’t link or it will say will run in software mode in the glinfolog in which case you can search for the word software, or it will run very slow.

On Nvidia it will work for Nv4x and higher (so 6x00 and higher). While cards prior to G80 don’t support “real” dependent loop, it is possible to break from the loop using a non-constant variable. So on such cards, the compiler would declare a static loop with a dependent break instruction. Anyway, as uniforms are considered constants on pre-G80 hardware, it won’t be an issue for you: the compiler would recompile the shader if the uniforms are changed. Note this only applies to Nvidia hardware, I can’t make any statements with ATI. Still, AFAIK ATI had better fragment branching then Nvidia in the older generations (pre DX10).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.