I have a uniform block in my shader, which I'm accessing within a loop:
#version 330 core
const int MAX_LIGHTS = 8; // Maximum amount of lights
uniform int numLights; // Actual amount of lights (Cannot exceed MAX_LIGHTS)
layout (std140) uniform LightSourceBlock
{
vec3 position;
[...]
} LightSources[MAX_LIGHTS]; // Light Data
void Test()
{
for(int i=0;i<numLights;i++)
{
vec3 pos = LightSources[i].position; // Causes "index must be constant expression" error on Nvidia cards
[...]
}
}
This works fine on my AMD card, however on a Nvidia card it generates the error "index must be constant expression".
I've tried changing the shader to this:
#version 330 core
const int MAX_LIGHTS = 8; // Maximum amount of lights
uniform int numLights; // Actual amount of lights (Cannot exceed MAX_LIGHTS)
layout (std140) uniform LightSourceBlock
{
vec3 position;
[...]
} LightSources[MAX_LIGHTS]; // Light Data
void Test()
{
for(int i=0;i<MAX_LIGHTS;i++)
{
if(i >= numLights)
break;
vec3 pos = LightSources[i].position; // Causes "index must be constant expression" error on Nvidia cards
[...]
}
}
I figured this way it might consider "i" to be a constant, but the error remains.
So how can I access "LightSources" with a non-const index, without having to break up the loop and just pasting the same code below each other a bunch of times?