You are absolutely right. There are limits. I almost forgot about that. The number of varyings does not scale with the number of lights since I only pass position, normal and texcoord to the fragment shader and do everything else there. The other limits differ from GPUA “Graphics Processing Unit” is a specialized circuit designed to rapidly manipulate and alter memory in such a way so as to accelerate the building of images in a frame buffer intended for output to a display. GPUs are used in embedded systems, mobile phones, personal computers, workstations, and game consoles. to GPUA “Graphics Processing Unit” is a specialized circuit designed to rapidly manipulate and alter memory in such a way so as to accelerate the building of images in a frame buffer intended for output to a display. GPUs are used in embedded systems, mobile phones, personal computers, workstations, and game consoles. and are quite interesting to explore.
My old Radeon 9700M suffers the most from the instruction limit. I guess loops are unrolled and functions are inlined on this GPUA “Graphics Processing Unit” is a specialized circuit designed to rapidly manipulate and alter memory in such a way so as to accelerate the building of images in a frame buffer intended for output to a display. GPUs are used in embedded systems, mobile phones, personal computers, workstations, and game consoles.. The second limit is that uniform arrays like g_LightColor[] can only have up to 128 elements (compiler error otherwise). In addition, every element beyond [39] seems to be vec4(0.0) for some reason. But this limit is hardly relevant because of the instruction limit. At the moment, I can haz 10 light sources and it renders Sphere(256, 256) at 81 fps (Lighting.j3md at 11 fps).
My Intel candidate doesn’t seem to suffer from an instruction limit or there’s no unrolling / inlining. The DevGuide also says “unlimited” for SM 4.0. No idea if that somehow transfers to GLSL120. The problematic limit here is the overall uniform limit. At the moment I can haz 35 lights and it renders Sphere(256, 256) at 14 fps (Lighting.j3md at 0 fps).
To test if there is an instruction limit or a uniform limit, I used a block like this:
uniform vec4 g_LightPosition[NUM_LIGHTS];
uniform vec4 g_LightColor[NUM_LIGHTS];
uniform vec4 g_LightColor2[NUM_LIGHTS];
uniform vec4 g_LightColor3[NUM_LIGHTS];
//...
for (int i = 0; i < NUM_LIGHTS; i++)
{
finalColor += doLighting(N, E, g_LightPosition[i], g_LightColor[i]);
doLighting2(N, E, g_LightPosition[i], g_LightColor[i], finalColor);
doLighting2(N, E, g_LightPosition[i], g_LightColor2[NUM_LIGHTS-i-1], finalColor);
doLighting2(N, E, g_LightPosition[i], g_LightColor3[i/2], finalColor);
doLighting2(N, E, g_LightPosition[i], g_LightColor[i/4], finalColor);
doLighting2(N, E, g_LightPosition[i], g_LightColor2[i/8], finalColor);
doLighting2(N, E, g_LightPosition[i], g_LightColor3[i/16], finalColor);
finalColor += g_LightColor3[NUM_LIGHTS-1];
// ... insert more stuff here to go for the instruction limit
}
The GLSL compiler seems to be smart enough to remove unused uniforms. If I remove the “2″ and “3″ in the function call, the instruction count stays the same but there are less uniforms used. I used different indexes to prevent compiler magic.
Finally, the only limit my nVidia GTX 275 seems to have to face is the element limit of 256 for uniform arrays (g_LightPosition[256]). One can circumvent this by simply defining “g_LightPosition2[NUM_LIGHTS - 256]“. I did not encounter any other limit. This GPUA “Graphics Processing Unit” is a specialized circuit designed to rapidly manipulate and alter memory in such a way so as to accelerate the building of images in a frame buffer intended for output to a display. GPUs are used in embedded systems, mobile phones, personal computers, workstations, and game consoles. is a real beast. At the moment I can haz 35 lights and it renders Sphere(256, 256) at 93 fps (Lighting.j3md at 5 fps).
Let’s see where the journey takes us. At the moment, I have a brain parallax from trying to understand parallax mapping, but it’s just a matter of time to kill this brain bug.