• Advertisement
Sign in to follow this  

GLSL uniform array

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

If you intended to correct an error in the post then please contact us.

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 <= 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]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
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 this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement