I'm trying to pass a point light from an array to a CalcLight function in a fragment shader. It works when I hard code in the value, but not when I use a loop. Here's the code:
#define TOTAL_LIGHTS 2
struct PLight
{
vec4 pos;
vec4 diff;
vec4 spec;
vec4 amb;
float con;
float lin;
float quad;
};
layout(std140) uniform Light
{
PLight pLights[TOTAL_LIGHTS];
}light;
vec3 CalcPoint(in PLight p)
{
...
}
When I pass in the light from main using hard coded values it works fine.
void main()
{
...
pointLight += CalcPoint(light.pLights[0]);
pointLight += CalcPoint(light.pLights[1]);
...
}
But, when trying to use a loop, the first light works fine but not the second.
for(int i = 0; i < TOTAL_LIGHTS; i++)
pointLight += CalcPoint(light.pLights[i]);
Any thoughts as to why the loop isn't working?