GLSL dynamic looping?

Originally posted by Golgoth:
so much fuzz for basic stuff… I m having a nightmare, someone wake me up!
This stuff is basic in the vertex shader where those lighting state comes from and none of the above workarounds are needed.
It’s a little more advanced inside the fragment shaders because they don’t support the indirect uniform adressing.

Well, you could do glUseProgram(programObjs[lightCount-1]) instead.
Of course!

This stuff is basic in the vertex shader where those lighting state comes from and none of the above workarounds are needed.

I ve tried transferring everything in the vertex shader already and kept only this in the Fragment shader:

It’s a little more advanced inside the fragment shaders because they don’t support the indirect uniform adressing.
Advanced??!!! I had another word in mind! :slight_smile:

As for multi-texture, it depends on what you mean with that.

Well, let me try to give you the big picture. Here s a pseudo FFP Render sequence!

Render()
{
Enable Lighting
Set Global States
Set Render States (Including Muti-Texture State)
Draw primitives with Lighting State
Disable Lighting
Set Render States
Draw primitives without Lighting State
}

Anyway you move this around is not really important here… we just want to play with shaders like blocks of code and move them around dont we?

First, a question that comes to my mind is: can way expect to do:

If (Lighting)
SetLightingShader()
If (MultyTexture)
SetMultyTextureShader()
If (Fog)
SetFogShader()
If (PolygonOfsset)
SetPolygonOfssetShader()

DrawPrimitive()

Communicate between shaders and draw a single pass?

or one shader = one pass?

In my FFP, as it is for now, each primitive have an array of render states, a shader is consider as a render state, and it is always insert as the first Render State in the array. Since it overrides lots if not all the Render States… I m facing choices here…

1 - Replace all RSs with one big shader with all RS and lots of if (condition) in it!
2 - Replace all RSs with an Array of shaders: One shader per RS!
3 - Insert one or more shader(s) among the FFP RSs!

Since we cant process x number of lights and/or textures inside a shader effeciently… can we really get rid of the FFP at the moment?

What would be consider as good design when introducing shaders in a FFP?

You can only have one shader per pass. But what you might want to do is to make a so called über-shader that does all passes at once, if that’s possible in your case. So you basically just pass a boolean uniform for those conditions, like “Lighting” and “MultiTexture” etc. and use that in your shader.

Speaking on boolean uniforms, another option for the loop is to do this:

uniform bool count[8];
...

for (int i = 0; i < 8; i++){
    if (count[i]){
        ...
    }
}

If your count is for instance 5, you pass an array of booleans where the first 5 elements are true and the rest are false. In this case, since you have a compile time constant as your loop count the compiler will be able to unroll the loop, and it should also be able to handle the static branching so that you don’t do unneccesary work. Depending on instruction count, this might work on PS2.0 hardware too.

You can only have one shader per pass.
Slap… Ouch!

But what you might want to do is to make a so called über-shader that does all passes at once
So basicly take all FFP RenderStates and Stack it into a vertex and an fragment shader… and Slap… Ouch!

If your count is for instance 5, you pass an array of booleans where the first 5 elements are true and the rest are false. In this case, since you have a compile time constant as your loop count the compiler will be able to unroll the loop, and it should also be able to handle the static branching so that you don’t do unneccesary work.
Already tried this and for some ocus pocus reason the result is this:

It all link and compile successfully, the Boolean condition are doing their job fine but, it takes as much process going through the entire loop with 1 light enabled then having 8 lights enabled! try it and tell me I m taking crazy pills!

So basicly take all FFP RenderStates and Stack it into a vertex and an fragment shader… and Slap… Ouch!
if you were doing it on the cpu (ideal world) then this is what yould do, with new ati cards apparently this sort of choices are quite fast + with newer cards from now on this is only gonna get faster (theyre becoming more like cpus)

zed, could you explain to me, why this is going to be this way? Are modern GPUs that fast at branching and that alergic to shader-switches or what is the reason?

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