Creating a GLSL Arrays of Uniforms?

Miles picture Miles · Nov 11, 2011 · Viewed 61.3k times · Source

I would like to leave OpenGL's lights and make my own. I would like my shaders to allow for a variable number of lights.

Can we declare an array of uniforms in GLSL shaders? If so, how would we set the values of those uniforms?

Answer

datenwolf picture datenwolf · Nov 11, 2011

Yes this is possible. You declare uniform arrays similar to how you'd do it in C, e.g.

uniform float v[10];

Then you can set their values using glUniform{1,2,3,4}{f,i}v

GLfloat v[10] = {...};
glUniform1fv(glGetUniformLocation(program, "v"), 10, v);