PDA

View Full Version : More than 8 lights?



Dennis
09-17-2011, 01:06 PM
Hello everyone,

I've seen many times car-racing games with car-lights, of games with many torches on the walls.

But OpenGL does only support 8 lights.
So I don't really understand how those games could have more than 8 lights.
For example more than 2 cars with each 2 lamps for and 2 behind.
Or games with more than 8 torches on the walls or floors.

I hope someone could tell me more about how to do this.

Thanks,
Dennis

ZbuffeR
09-17-2011, 01:53 PM
Some solutions, some can be combined :
- multiples passes to add-blend lights by packets of 8
- only use 8 nearest/biggest lights for dynamic lighting
- average lights to group the most prominent values, depending on the position in the scene (I think quake3 engine does this to light dynamic geometry with static lights, a single light direction is kept)
- use deferred lighting/shading : one pass to rendering geometry and store for each pixel the normal, color, other parameter, then render a quad with custom shader for each light.

mhagain
09-17-2011, 05:45 PM
It's also the case that not everything uses OpenGL lighting (the Quake 3 engine doesn't, for example). ;)

Dark Photon
09-17-2011, 06:29 PM
But OpenGL does only support 8 lights.
As the responses you've gotten allude, this is not really true.

While old fixed-function OpenGL only supports 8 light sources at a time (and only computed per vertex at that), you can write your own shaders to support any number of lights you want with OpenGL, in many different ways (Forward Shading, Deferred Shading, Deferred Lighting, Light-indexed Deferred Rendering, pre-baked light maps, precomputed radiance transfer, etcetc.), in different combinations, with more physically-correct lighting equations, and also have these lighting computations take place "per pixel or per sample" (which looks tons better) rather than per vertex.

Many games including many car racing games support bunches of light sources with Deferred Rendering techniques. Need for Speed: The Run, for instance. Or Grand Theft Auto IV. These and other games write their own shaders to do deferred rendering in D3D, OpenGL, or game console-specific environment.

Still, a few games like God of War III try to support bunches of lights by merging real lights into a much smaller number of "virtual point lights" (the lighting in this isn't very realistic looking IMO). But it all depends on the level of fidelity your shooting for (and the platform(s) you're targeting).

If you want some links to good Deferred Rendering tutorials/etc., let us know (have collected a ton) and we can point you to a few of the better ones for getting started.

mhagain
09-18-2011, 04:32 AM
It's also very useful to run a game through GLIntercept (or PIX if D3D) and have a look at what it's doing behind the scenes. You won't get copy/paste code but you might get some useful ideas.

Dennis
09-18-2011, 06:21 AM
Thanks for all quick responses.

So I have to create the "lights" by myself, by calculating the color for each pixel.

I was just wondering how those games did this, but I should be very pleased if you should give me a few links to deferred rendering tutorials.

Dark Photon
09-19-2011, 06:21 AM
I should be very pleased if you should give me a few links to deferred rendering tutorials.
Sure. Here are a few of the earliest ones that're pretty good. Don't get caught up on the "how" they're doing things (GPUs have changed since then) or their limitation lists, but focus on the "what" they're doing, and "why". Deferred Shading (Hargreaves, GDC 2004) (http://artis.inrialpes.fr/Membres/Olivier.Hoel/deferred_shading/DeferredShading_gdc.pdf) Photo-realistic Deferred Lighting (Calver, 7/2003) (http://www.beyond3d.com/content/articles/19/1)Once you've got a feel for what's going on, these few will help you get your terminology straight and develop a deeper understanding of the various Deferred Rendering techniques: Deferred Shading Shines. Deferred Lighting? Not So Much. (Stone, 5/2009) (http://gameangst.com/?p=141) Deferred lighting approaches (Hoffman, 6/2009) (http://www.realtimerendering.com/blog/deferred-lighting-approaches/) Deferred Rendering for Current and Future Rendering Pipelines (Lauritzen, SIGGRAPH 2010) (http://visual-computing.intel-research.net/art/publications/deferred_rendering/)

nickels
09-19-2011, 01:48 PM
Lightmaps. Alluded to above, but some references:
lightmaps (http://www.gameversity.com/index.php?action=showtutorial&id=9&PHPSESSID=hj5ud tb9l8gue2hk31kmn921b7)

Unfortunately lightmaps lead directly into the task of building and understanding a world editor, no mean feat. A good source is the quake3 source code, which has their engine's world editor code (including the lighting pass). (Search quake3 download id software).

Then there is the magic of combining lightmaps with dynamic lights, and of light/shadowing dynamically moving objects, etc..., spherical harmonic lighting, etc...

Another good source for understanding how games work with lights is to download the unreal editor (free) and make a few simple levels. Get a book and learn how to place some lights in the editor and with your graphics knowledge you should be able to understand at least the approach that the unreal engine is taking to lights.

Deferred lighting is definitely a great approach to immediately get beyond the few lights bottleneck for rendering simple opengl scenes.
Its cool stuff; a bit overwhelming when you consider all the possible paths to implementation.
Wish I had more time to play with this stuff!