Referencing arrays in Fragment Programs

Hello,
I am trying to reference an array that is passed in as a uniform parameter with another uniform parameter in a fragment shader, like this:

uniform mat4 matrices[20];
uniform int MatIndex;

void main(void)
{
  vec4 result = somevector * matrices[MatIndex];
}

But the linker complains that the indexing must use a compile-time constant…

is that true for fragment programs and not for vertex programs? I do not understand why this could be a fragment program limitation.

please help.

Most (all?) hardware does not support indexing into constants in the fragment shader. If you need to support this, store your constants in a small texture setup to use GL_NEAREST filtering and fetch your data from the texture with the appropriate texture coordinates.

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