Skip to main content
GameDev.net gamedev.net
🔒 Locked

Only 8 Lights?

Started by neonfaktory Dec 14, 2002 at 12:40 PM 13 replies 800+ views
Original Post
neonfaktory
neonfaktory
Ok, I have learned that in OpenGL you can SAFELY have up to 8 lights - more than that might not be supported. Now I have a question to all you 3D computar grafix theory people out there... How would you handle a game where there are random explosions here and there (depends on the situation) and you wanted to have them cast light on surrounding models, walls, etc.? Since it is situation dependant, there could be 2 people shooting off 10 light-emitting rockets each, and that doesnt work to well with the 8 light minimum. I have a few ideas myself on how to solve the problem, but maybe someone can suggest something cool, because my ideas are not very elegant solutions ;\ .
weee!
neonfaktory
neonfaktory
AWWW... double post, my bad
weee!
johnnie2
johnnie2
In theory, it''s fine to have greater than eight lights. The only problem with surpassing that limit is that all lighting calculations fall out of hardware and into software, leading to what could be a tremendous slowdown when you go from that eighth to ninth light.

To get around the problem, you can do the lighting calculations on your own, use lightmaps, or one of many other possibilities.

RapscallionGL - arriving soon.
____________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
Yann L
Yann L
Up to 8 lights per face. In practice, what most people do, is to select the nearest (or strongest) 8 lights from a global light pool, for every object or entity. You then render this object with the selected lights enabled.

But there are a few things to note about this 8 light limit: it''s only valid on the fixed function pipeline. If you use vertex shaders, then only your vertex program will be the limit, as you code the lighting yourself. You can write vertex programs that easily support 32 or more lights. And it is going to be faster than fixed function lighting (at the same number of active lights), as you can use some tricks and shortcuts by removing parts of the lighting equations you don''t need.
LockePick
LockePick
It's 8 lights per polygon . That's the key. Only activate what lights are close enough to affect what you're drawing. A rocket shot straight up in the air doesn't need to light up the ground, so you disable it before drawing the ground and only enable the lights which you need too.

EDIT: Bah, too slow
------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It's all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

[edited by - LockePick on December 14, 2002 1:53:32 PM]
Yann L
Yann L
Hehe

BTW: neonfaktory, you can delete your double posts by deleting your first topic.
neonfaktory
neonfaktory
Yeah, i tried that, but when I click "send" in the mini window that pops up when you click the "delete thread" button, it comes up with that wacky "Page Cannot be Displayed" message, so I just figured only mods could do it or something :\

In response to the topic, I was thinking of the "8 most powerful lights" solution, but couldnt that possibly get some glitchy looking results? Lets say you have a bright light from behind, all of a sudden 8 slightly brighter lights show up on the OTHER side, the light from behind will "turn off" for the duration of the new lights...

Hmm.. I considering doing my own lighting, because what I''m looking for is pretty basic. I wouldnt mind having my whole model just light up with a uniform light based on the surroundings - ack, I dunno.. I''m still pretty new as you may have guessed, and I wouldnt kow where to begin if I did it myself. THanks for the quick feedback, however Any other suggestions welcome
weee!
Yann L
Yann L
Yeah, light popping artifacts might appear. It depends on your lighting. On smaller object, lit by a few large lightsources, it won''t be visible. But say you have a large spaceship moving along a launching facility in a spacestation, with hundreds of small position lights along the wall, then the artifacts will most likely be extremely visible.

Some possible solutions:

* if you have blinking or flickering lights, then try to synchronise there blinking/flickering with the light selection algorithm. That way, you can elegantly hide the fact that no more than 8 lights can be active per object and per frame.

* don''t simply switch from one set of nearest/strongest lights to another, but do a smooth fade. Won''t solve the issue, but might make it less noticeable.

* Instead of simply taking the nearest sources, approximate the light''s general influence on the object, and select the ones with the highest impact. Might fool the brain, as it is trained to ignore small light differences, if overwhelmed by large ones.

* If a light is near an object, but will only light faces invisible from the current viewpoint (out of the frustum, occluded, backface culled, etc), then you can ignore that light.

* Use vertex shaders and/or perpixel lighting. Will introduce other problems though. But no lighting solution is perfect.

* Use lightmaps. Infinite number of lights, but they can''t be dynamic (well, they could, but dynamic lightmaps are very restrictive and performance hungry).

/ Yann
OrangyTang
OrangyTang
You could use the 4 most influencial lights, and then approximate the rest in the remaining 4 lights - combining lights in a similar direction into one, or change it to 2 actual and 6 averaged (one for each major direction).

Done well would solve your rapid switching problem you mention, but i''d question how often that would actually happen.
neonfaktory
neonfaktory
I think I might implement my own "GLLight" class. Basically keep an x,y,z coordinate and intensity value, and then do some simple linear calculation to apply a color "mask" to each of the polygons based on distance. Sound like it will work nice? And now that i think of it, I don''t know how to apply a color mask to a textured polygon, if anyone would be so kind to explain or direct me Thanks for the help
weee!
DarkHamster
DarkHamster
isn''t enabling/disabling a light source a large overhead process that should be avoided as much as possible?



"There is no dark side of the moon really,
As a matter of fact, its all dark."


"There is no dark side of the moon really,
As a matter of fact, its all dark."
zedzeek
zedzeek
as others have said only use the nearest/brightest lights
ALSO if 8 is not enuf u can easy extent that to 16/24/32/48 etc
draw the first 8 lights then enable blending with ONE ONE draw the next 8 lights etc

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
JD
JD
Most people use dynamic lightmaps and/or per-pixel attenuated colored lights using texture stages. That way you can have infinate lights in a scene. I wouldn''t use hw lights because for it to look good your geometry needs to be highly tesselated. I think I can get away with 15 colored att. per pixel point/spot lights and even more when I get to optimizing my code. I think 30 is not out of the question on gf2 hw. Perhaps 100 or more on gffx hw. Ambient is first pass, attenuation is second pass using 2D map and z-in texture factor, texturing is third pass. These are not shadow casting lights, if they were stencil shadow volumes would eat you alive They''re also not bump mapped. I think nvidia has a demo of hw lights, think like 300 of them per frame if I remember correctly. Runs fast on my gf2. Per-pixel lights look much better than hw lights. You get that soft falloff that looks really good in dark environment type games.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.