OpenGL and Lighting

Started by
8 comments, last by Sqwiddly 22 years, 8 months ago
Okay sorry if the question I''m about to ask is very easy to answer and requires no thought, but I''m a bit dazed at how the OpenGL lighting system works. I looked in the header and I see GL_LIGHT0 - GL_LIGHT7. Ok I understand that OpenGL can render 8 max lights, but how do you go about rendering many lights? I''ve seen BSP levels that have about 200-400 lights! I''m guessing that the BSP engines just show the lights which are nearest and visible in each room but what if you are in a big open area (such as terrain or any outside environment) and you have to render many street lights and sunlight from above? Do the level editors just cleverly place lights so that OpenGL can pull it off? As you see I''m pretty stumped on the subject so if someone could kindly explain this lighting system. I know that I may sound a bit amateur but I haven''t ever really used OpenGL or Direct3D before, I''ve only used wrappers around those like Genesis3D and CrystalSpace etc. Thank you in advance!
Advertisement
I''m not exactly sure about that BSP level stuff, but if you want more than 8 lights on a polygon you can render the polygon with multiple passes changing the light properties each time.
----------------------------www.physicsforums.comwww.opengl.org
Well most BSP engines don''t use real dynamic lighting, or at least not for all of their lights. Mostly they use lightmaps and for some semi-dynamic effects, animated lightmaps. I know this is what Quake and Half-Life do. (Not sure about Q3 or UT or other newer games though)

Dirk "Scarab" Gerrits

''If knowledge is power, than to be unknown is to be unconquerable.''
- Unknown Romulan Centurion
Dirk =[Scarab]= Gerrits
Scarab is right. What they do is simply calculate their own lighting values; store them in textures, called lightmaps; and blend these lightmaps over the scene.

Only problem: since everything is precomputed, lights can''t be changed.

Y.
Hmm yes that makes a lot more sense. I understand it all a little more now. But what about outdoor based engines? Games like Tribes, Asherons Call etc. Do they just pre calculate lightmaps and display them like a BSP engine would? I''m not thinking about making a Massive online RPG, those were just examples right off of my head.
Suppose you have a room with like 20 or so lit candles or light bulbs ot whatever. Or a terrain lit by many objects, moving around. You draw the scene with only 8 lights, then, on a seccond pass, you switch to the next 8 lights and redraw the triangles affected by the lighting, using the appropriate blend functions. If needed, render the polygons again, with the next set of lights and so on, until all lights have been processed.
Should work, maybe a bit slower.
The OpenGL reference manual says that the glLight funcions accept a value for the light number ranging from 0 to GL_MAX_LIGHTS. Weird. I checked my gl.h header and GL_MAX_LIGHTS is 0D31h.



Free your mind.
Free your mind.
u should never need more than 4 lights lighting one vertice at once ie turning on more lights normally wont make that much of a difference

heres what u do
for each mesh
{
turn on the 4 most important/closest lights
draw mesh
}

of course u wouldnt want to be changing the lights all the time perforamce reasons.
also according to the nvidia perfomance faq using 8 lights is 5x slower than 1 light. ie using a lot of lights doesnt mean a slight perfroamce drop
ZedZeek you''re right, except that there''s not only nVidia boards on the market, plus nVidia cards are weak when it comes to lighting.

(I know another card with a L engine more than 8 times faster, but it''s not publicly released *yet* )

Basically you should not care too much about what can be done today since the time it''ll take you to write an engine, at least a year would have passed.

-* So many things to do, so little time to spend. *-
-* So many things to do, so little time to spend. *-
OK, So basically I run through the lights which are nearest to the camera and render those in multiple passes using the GL_LIGHT0 through GL_LIGHT7. Makes sense to me, but that wouldn''t cause any flickering? I assume it wouldn''t as long as I keep the light usage down a bit. Well thank you everyone, I understand it all now. Peace
>>OK, So basically I run through the lights which are nearest to the camera <<

no for each vertice/mesh choose the closest/most important lights to it + use those, check glut theres a demo that does the exact same thing.

this works on the priciple say youre outside whats the most important light, the sun OK so use that say the person is carry a flaming torch, how much light does it cast on the tree 50m ahead. bugger all so theres no need to have the torch light switched on when u draw the tree

This topic is closed to new replies.

Advertisement