Array indexing

Hi all, does anyone know if GLSL 1.1 supports non constant array indexes?

I am storing the bone indices in the secondary color channel as single bytes. After accessing them after they have been expanded to floats in the shader requires a cast, which removes the constness of the indices,

example:
// this is what i wanted to have happen
bonepose.x = pos = dot(bones[gl_SecondaryColor.x + 0], gl_Vertex);
bonepose.y = pos = dot(bones[gl_SecondaryColor.x + 1], gl_Vertex);
bonepose.z = pos = dot(bones[gl_SecondaryColor.x + 2], gl_Vertex);

// this is with the cast to integers that i mentioned
bonepose.x = pos = dot(bones[int(gl_SecondaryColor.x) + 0], gl_Vertex);
bonepose.y = pos = dot(bones[int(gl_SecondaryColor.x) + 1], gl_Vertex);
bonepose.z = pos = dot(bones[int(gl_SecondaryColor.x) + 2], gl_Vertex);

it may also be important to mention that glsl seems to require the explicit casting. Does anyone have any opinions of how to do this properly in glsl 1.1? It doesn’t seem I’m on the right path, thanks!

Hi all, does anyone know if GLSL 1.1 supports non constant array indexes?

There has never been a restriction on array indices to be constant. Only the array specifier (that says how many elements there are in the array) must be a compile-time constant.

Thanks Reinheart, cool name btw!, and the problem is partially solved with your help, i should have mentioned that the example code i posted was nested inside of this statement, where numBones is a uniform int.

if(numBones > 0)
{

}

My guess was that there may have been a bug in the glsl optimizer that causes instructions to be culled improperly in particular cases when branching is involved.

It’s not a bad thing, the branches should not have been there in the first place. Thanks so much for your help! It was really beneficial to know for sure that the indexing itself was not the problem. Thanks again!

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