tags:

views:

363

answers:

3

How should I implement more than 8 lights in OpenGL?

I would like to render unlimited amounts of lights efficiently.

So, whats the preferred method for doing this?

A: 

http://www.opengl.org/resources/code/samples/mjktips/VirtualizedLights/VirtualizedLights.html

the number one hit when you google "render more than 8 lights opengl"

Kenny Winker
That's outdated. The article is from 1997...
Nils Pipenbrinck
+1  A: 

OpenGL lights is a simplistic system, that as far as I know is already in the deprecated list. You should handle lights yourself by writing a shader. Take a look here.

Kornel Kisielewicz
the tutorial says "therefore the best approach is to compile different shaders for different numbers of lights." umm... thats not really what i want to do, since i can move in the world and sometimes there might be 100 lights rendered, sometimes 10 lights... i wouldnt want to write up to 2000 shaders for every possible combination of visible lights. Or did i understand something horribly wrong :/
+8  A: 

Deferred shading.

In a nutshell you render your scene without any lights. Instead you store the normals and world positions along with the textured pixels into multiple frame-buffers (so called render targets). You can even do this in a single pass if you use a multiple render-target extension.

Once you have your buffers prepared you start to render a bunch of full-screen quads, each with a pixel shader program that reads out the normals and positions and computes the light for one or multiple light-sources.

Since light is additive you can render as much full-screen quads as you want and accumulate the light for as much light-sources as you want.

A final step does a composition between your light and the unlit textured frame-buffer.

That's more or less the state-of-the-art way to do it. Getting fog and transparency working with such a system is a challenge though.

Nils Pipenbrinck