Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Sqwiddly

OpenGL OpenGL and Lighting

This topic is 6196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. *-

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
>>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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!