Hi people, I’m new to the world of OpenGL shaders, and I’m looking for help with a problem I’ve come across.

I’m developing an application with OpenGL shaders and GLSL. Basically, I have one large loop that needs to be executed on each pixel. Because this loop should be executed on the pixels, I have put it in the fragment shader. The problem is that when I go to compile the fragment shader, I get an error because the number of elements in my loop exceeds the maximum possible size for a fragment shader.

Here’s the current code for my fragment shader, which compiles and outputs the right image:

```
#version 430 core
#define M_PI 3.1415926535897932384626433832795
in vec4 gl_FragCoord;
uniform int DIM_N;
uniform int DIM_M;
uniform vec4 redlogs[256]; // red logons
uniform vec4 greenlogs[256]; // green logons
uniform vec4 bluelogs[256]; // blue logons
uniform vec2 dims;
out vec4 fColor;
void main()
{
float x = gl_FragCoord.x/dims.x;
float y = gl_FragCoord.y/dims.y;
fColor = vec4(0.0, 0.0, 0.0, 1.0);
for(int m = 0; m < DIM_M; m++){
for(int n = 0; n < DIM_N; n++){
fColor[0] += redlogs[n+m*DIM_N][0] * sin(n*M_PI*x) * sin(m*M_PI*y);
fColor[0] += redlogs[n+m*DIM_N][1] * sin(n*M_PI*x) * cos(m*M_PI*y);
fColor[0] += redlogs[n+m*DIM_N][2] * cos(n*M_PI*x) * sin(m*M_PI*y);
fColor[0] += redlogs[n+m*DIM_N][3] * cos(n*M_PI*x) * cos(m*M_PI*y);
fColor[1] += greenlogs[n+m*DIM_N][0] * sin(n*M_PI*x) * sin(m*M_PI*y);
fColor[1] += greenlogs[n+m*DIM_N][1] * sin(n*M_PI*x) * cos(m*M_PI*y);
fColor[1] += greenlogs[n+m*DIM_N][2] * cos(n*M_PI*x) * sin(m*M_PI*y);
fColor[1] += greenlogs[n+m*DIM_N][3] * cos(n*M_PI*x) * cos(m*M_PI*y);
fColor[2] += bluelogs[n+m*DIM_N][0] * sin(n*M_PI*x) * sin(m*M_PI*y);
fColor[2] += bluelogs[n+m*DIM_N][1] * sin(n*M_PI*x) * cos(m*M_PI*y);
fColor[2] += bluelogs[n+m*DIM_N][2] * cos(n*M_PI*x) * sin(m*M_PI*y);
fColor[2] += bluelogs[n+m*DIM_N][3] * cos(n*M_PI*x) * cos(m*M_PI*y);
}
}
}
```

So that compiles, but when I change the dimensions of redlogs[256] to something like [1024], the shader will not compile… I’m wondering what I should do instead? Is there a way to use larger arrays on the GPU?

Thanks!