unlimited number of lights, how?

hello guys,

i want to render a scene with unlimited number of lights. but i don’t know how to do that. especially how to transfer the lighting information to the gpu? via texture map?

is there any example i can look at? thanks.

You can feed the per-light data to shaders via uniforms (in combination with standard gl_LightSource structure if applicable). This way you don’t get ‘unlimited number of lights’ in one pass, just way more than 8, depends on your hardware.


You can also do the “standard” thing for lights, which is have a pass over the geometry to compute each light. This is generally useful for doing lighting with multiple shadow textures and such.

hi, thank you. so i use one pass for one light? but how do i blend the results together?

render them to a fbo and read back to cpu?


Well, unlimited is of course out. :wink: But I get your point: lots of lights.

You should probably clarify whether you want lots of light points/particles (bright spots or areas that don’t necessarily illuminate things around them but just appear bright (possibly blending a little brightness in a radial area around them), OR you want lots of light sources, where each point light source properly illuminates the objects around it.

If you really do want the latter (lots of light sources), let me suggest reading up on light pre-pass (aka deferred lighting) and light indexed deferred rendering.

Here are some links to docs on these. There was a lot of info on Light Pre-pass in a course at SIGGRAPH this year, so I’m linking you to the course notes:

Now instead, you could use the standard GL/D3D rendering method (throw the entire scene at the framebuffer, and apply materials/textures/compute lighting for each object as you go (either one pass with a shader that applies ALL the lights in one go, OR one light per pass, blending the results). But for lots of light sources, these have some pretty big disadvantages.

thank you so much.

what i’m doing is an open source modeling tool, not a game. but latter, i want to give a ray tracer to the tool. so the user sets up lights with the tool and render with the ray tracer. i just want the opengl scene look closer to the ray traced result. it is quite possible that the scene have more than 20 lights. ya, you are right, a lot of lights.

i have roughly studied all the options. i guess i will use glsl shader for multiple lights combining with multiple passes, if there are even more lights.

i just learned Deferred Rendering and had a quick look at a paper. but i guess, i should not use it, because it is hard to achieve complex material with this method, and often the G-buffer is smaller than the screen space to speed up the rendering process. since i’m working on a modeling tool, i think showing the details of the model is very important. and i want to implement some complex “mud” like material as those used in zbrush.

thank you for your answer. it is very helpful. i learned a lot.

thank you.

By Deferred Rendering, I infer from your wording you mean Deferred Shading.

Deferred Shading != Deferred Lighting (the latter aka Light Pre-pass)

With Deferred Rendering, you blast material properties into the framebuffer, and go back and light them later. With Deferred Lighting, you accumulate light field contributions in the framebuffer, and go back and shade in your materials later.

With Deferred Lighting you don’t have to limit your material complexity like you do with Deferred Rendering.