I am using uniform arrays for some lighting calculations. All this works without problems on NVidia but I got some reports from ATI users that they’d have problems with it.
Basically what I do is to collect a number of light sources and upload them to a uniform array like this:
glUniform3iv(lightrange_index, 1, mNumLights);
glUniform4fv(lights_index, mNumLights, mLightData);
This is some example of how they get used in the shader:
uniform ivec3 lightrange;
#ifdef MAXLIGHTS256
uniform vec4 lights[256];
#else
uniform vec4 lights[128];
#endif
vec4 GetLight(vec4 pixelpos)
{
vec4 dynlight = vec4(0.0,0.0,0.0,0.0);
for(int i=0; i<lightrange.x; i+=2)
{
vec4 lightpos = lights[i];
vec4 lightcolor = lights[i+1];
lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
dynlight += lightcolor;
}
return dynlight;
}
Does anyone have an idea why there seem to be problems on ATI?
On my own Geforce 8600GT this is a lot faster than using uniform or texture buffers to transfer the light data so I don’t really want to change it.