   Multiple light sources with OpenGL and Cg
  By following the Cg tutorial and developing my engine using OpenGL, I've been able to implement the Per-Pixel Lighting model. However time has come to make a little more generic this lighting model and I really need some help from you guys. To begin with, I need the engine to be able to remove and add lights in run time, to handle several light sources with the best possible performance. I know this can turn into a daunting task, but I would want to keep things as simple as possible.I render my objects using vertex arrays, pre calculated normals and a simple texturing. I would like to have some feedback on what to do next to get this working more generic considering the following.Lighting with the fixed function pipeline OpenGL offers, is not very flexible; it has a limit of source lights, besides it can not  be combined with the rest of the shader effects. Anyways I would like to know if is there another benifit of computing the lighting in a shader than using the OpenGL fixed function?The Per-Pixel lighting model I have implemented uses a light array, it accumulates the diffuse and specular according to the amount of light sources:...for(int i = 0; i < numberLightSources ; ++i){getLighting(..., lightSource, diffuseLightResult, specularLightResult);diffuseAcumm += diffuseLightResult;specularAcumm += specularLightResult;}...However I don't understand how a dynamic array can be manage within the Cg shader, is that possible? All code snippets I have found show a static array as the uniform parameter:...uniform Light light[10]...The other problem I have, and can't come up with a good solution, is how to provide the uniform parameters in a generic way, this parameters can be active or not:...cgGetNamedParameter(myCgProgram[0], "light[0].position");.. get more and more parameteres...cgSetParameterxf(.., );... set more and more parameters with different function callsIs there an existing wrapper to handle all this parametrization issues?I leave a screenshoot of how the engine looks now.[attachment=1631:screen2011-11-03.jpg] Any help will be appreciated. Thanks in advance .   
Anyways I would like to know if is there another benifit of computing the lighting in a shader than using the OpenGL fixed function?[/quote]Control.  When you have access to the actual code that's making the GPU do stuff, you become very powerful.However I don't understand how a dynamic array can be manage within the Cg shader, is that possible?[/quote]As far as I know, no.  My solution was to write a shader class that generates a shader based on the programmer's input; so you request a vertex program, a fragment program, but not a geometry program; specify 4 texture units and 5 lights, etc.  In your case, it's a simple matter of just changing the string literal of your input program, and having two shaders instead of one.