How to create GLSL arrays for multiple lights?
GLSL Arrays Each light we have defined (so far) is composed to 4 4-component vectors, ambient, diffuse and specular colour, along with the “position” (direction) vector. If we wanted to provide, for instance, 3 lights of this type, we *could* create 12 different uniform values, and set each of these uniforms individually.
Why do we need a GLSL structure for shaders?
GLSL allows us to bind these kinds of values together into a structure. The structure doesn’t provide many benefits other than keeping the namespaces of your code clean and allowing for declaring multiple uniforms of the same type, such as a “front” and “back” material.
Do you need pointers for a lights array?
The array types must be “sized” (have a specific, final size) in order to be usable, so no “pointer” types are available, but we don’t need them for this type of operation. We can define a “lights” uniform which is declared as a sized array of 12 vec4 elements:
What are the uniforms of a GLSL array?
GLSL defines two built-in Material uniforms gl_FrontMaterial and gl_BackMaterial. It is possible (though seldom done) to fill in these uniform values with glUniform calls rather than the legacy glMaterial calls.
What is the material struct structure in GLSL?
We are going to define a very simple Material struct which is a subset of the built-in gl_MaterialParameters structure (which also has an “emission” parameter). GLSL defines two built-in Material uniforms gl_FrontMaterial and gl_BackMaterial.
Can a GL handle array of structure indexing?
While glUniform *should* be able to handle array-of-structure indexing, it doesn’t actually support this type of operation in the real world. The built-in gl_LightSourceParameters are an array-of-structures, but apparently the GL implementations consider this a special case, rather than a generic type of functionality to be supported.