GLSL uniform array

Started by
3 comments, last by mod42 18 years, 6 months ago
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 <= size; i++)
    {
        for(j = -size; j <= 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]
Advertisement
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)
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
What about the fact that you are assigning a uniform variable a value within the shader?

Shouldn't uniforms be read only within the shader?

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

this was also a bug which I solved a little bit later. But the error is still there. I walked around that problem know by putting my filter kernel into a texture but thats not the ideal solution.

This topic is closed to new replies.

Advertisement