• 9
• 9
• 11
• 12
• 9

# GLSL uniform array

This topic is 4573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I hava a small problem with GLSL and an uniform array I want to use. I have something like this:
sampler2D tex;

uniform float filterKernel[25];
uniform int size;
uniform float xInc;
uniform float yInc;

varying vec2 texCoord;

void main(void)
{
vec3 color = vec3(0.0, 0.0, 0.0);

//We get the size as real filter size
size = size/2;

vec2 Inc;
int i,j;

for(i = -size; i &lt;= size; i++)
{
for(j = -size; j &lt;= size; j++)
{
Inc = vec2(xInc*i, yInc*j);
color += texture2D(tex, texCoord + Inc).rgb * filterKernel[(i+size)*size + j + size];
}
}

gl_FragColor = vec4(color, 1.0);
}


Is not very effective, I know, but this is not the point now. If I try to use this fragement shader I get the massege "error C5043: profile requires index expression to be compile-time constant" in the line where I access the array. I am using the a GeForce 660GT and the latest nvidia drivers. Greetings, mod42 [Edited by - mod42 on October 11, 2005 7:02:54 AM]

##### Share on other sites
Apprently whatever Cg profile NV use internally to support the compilation of GLSL doesnt support dynamic looping in the fragment shaders.

You'll either have to fix the loop size as a constant or ask NV to allow you todo it, as afaik your hardware can do it (dynamic branching and looping are major features of the SM3.0 profile)

##### Share on other sites
Hi

the problem is not the dynamic loop. When I change the inner loop statement from

color += texture2D(tex, texCoord + Inc).rgb * filterKernel[(i+size)*size + j + size];

to

color += texture2D(tex, texCoord + Inc).rgb;

the code compiles and does what I expect. But when I start to use the filterKernel array with an index unkown at compile time I get the error.

Greetings,
mod42

##### Share on other sites
What about the fact that you are assigning a uniform variable a value within the shader?

uniform int size;...void main(void){       ...    size = size/2;