Car headlights, tail lights, street lights (OpenGL supports 8 lights..) How?

Hey,

Hoping someone here can clarify a question I have regarding OpenGL and lights…

Im currently reading the OpenGL red book, and I have reached the lights chapter. Whilst skimming through the pages I discover a statement saying that OpenGL is guaranteed to only supports up to 8 light sources, anything above that is vendor specific. So…

Say that you are developing a car driving game, and wish to increase the atmosphere during night time driving by adding lights on the car and street, much like GTA (See URL below). Examining the car in GTA shows that head/tail lights seem to be transparent cubes with light sources inside… Maybe thats possible in DirectX, I dont know that API at all…
http://www.gouranga.com/images/gta3/gta3_216.jpg

I just dont see how this can be done in OpenGL with only 8 light sources, or is it necessary to use lightmaps for head/tail lights and cool street illumination, If I understand that concept correctly…

This is a common misconception among people that OpenGL only supports 8 lights…it doesn’t.

It supports 8 lights per object. You can have a gigillion lights in the scene, but only 8 are allowed to influence 1 object at a time.

Hope that helps.

DP

Thanx darkprophet,

Then its an entirely different matter :slight_smile: … Was getting cold feet here for a while.

You can also have more than 8 lights per object in OpenGL, if you use multiple rendering passes. Since shaders usually are additive for each light, simple use blending function ‘add’, change the lights and call the render method again. (this is probably what dp has meant with ‘at a time’).

Besides the fact that the “light” from the headlights actually look pretty fake but it’s difficult to see if they actually cast any light, all I can see is a flare which AFAIK is no guarantee there is actually a light source.

a huge percentage of lights in games are not really there. They are simulated using semi transparent textured quads to show some kind of glare, and then some are real, others might just effect the global ambient lighting in certain areas to give the illusion. Then there are other techniques like light maps which again give the illusion of lights where there are not real GL lights.

Endolf

Hey,

I took some better screen shots from Vice City, and I think there are definitely lights there, although it seems that they use light maps at night time, and they also display flares, if viewed from a correct angle. Think the lighting in GTA 3 is really nice, smooth atmosphere.

See the attached files for the headlights I’m talking about. Its the same with tail lights. I just thought that if you create a vehicle with 4 lights, then from what I understood before this post, was that you could only render 2 vehicles at a time, since 4 + 4 lights = OpenGL limit (at least thats what I thought, glad that wasn’t correct).

Peace

With shaders, you can do a whole lot more. Just google for Deferred shading, and you can see you can use any number of lights, only thing stopping you from using a gigillion is fillrate, but with deferred shading, you can reduce the size of the texture to speed it up, but thats another discussion for another day :slight_smile:

Yes, you can do multiple passes for N lights, but that becomes expensive on a character especially if you have skeletal animation as well…

Gotta love making game engines :slight_smile:

DP

IIRC, car headlights and other small lights are a combination of light flares for the screen effect and a simple projected texture for the illumination effect. They also combine the two headlights into a single projected texture rather than handle each individually (the rear lights don’t project any light at all).

Like most game graphics, it’s all smoke and mirrors. ;D

never underestimate the power of EYE_LINEAR! ::slight_smile:

PS. If you understood that joke, your a geek

Hehe, yea I guess the object in the mirrors are not as they appear :slight_smile:

Deferred shading looks like a fancy way to do lighting, but I don’t know too much about shaders, and from what I understand its a pretty experimental technique, so I guess Ill stick to the fixed function pipeline for a while, unless anybody knows of a nice tutorial or something for shader based rendering pipeline.

Looks like projected textures and some flares is the easiest way to get nice looking car headlights at during night time, as pointed out by Orangy Tang.

Thanks for clarifying the bit about 8 lights per object. I had recently misread that in the red book as well.