Jump to content
  • Advertisement
Sign in to follow this  
mcguile25

Lighting entire levels

This topic is 4458 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

Hey guys, I was wondering how to go about doing lighting in my game. Let's say I've got a level with 15 rooms. I am using Direct3D, so I'm assuming I'll be using D3DLIGHT9. I'm not using lightmaps or anything like that. So I guess my question is, how do most games without lightmaps do lighting? Do they just place a bunch of D3DLIGHT9 point lights in the various rooms? Obviously there's also a limit on the number of lights active in one scene (I think about 8 right)? Sorry this is so general, I'm just trying to get a feel for how I can light my entire level up efficiently and beautifully without lightmaps or such. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Do you really have to use D3DLIGHT9, y'know - pixel shaders are so much better [grin]

There are a huge number of tricks to this sort of lighting. It all depends on quite what sort of effect (and degradation thereof) you want to achieve...

Ambient lighting (remember, you can change it between draw calls [wink]) and directional lights are good ways of getting some sort of lighting into large areas of the scene for relatively little cost.

LOD Lighting is another option - put as many lights into the level as you want, but use some sort of algorithm to enable/disable lights according to their distance from the camera (or player). More specifically, you want to select N lights that will have the most significant influence on the final image.

hth
Jack

Share this post


Link to post
Share on other sites
Hey thanks for the response. Couple reasons why I am not using pixel shaders (yet): my video card is a piece and can't do pixel shaders and I haven't learned them yet. Hopefully both of these issues will get addressed sooner or later.

But yeah, I'm thinking about putting N number of lights in my level, and then determining which ones are closest and just enable those.

Share this post


Link to post
Share on other sites
You have the right idea. There's no limit on lights that can be enabled, but if you use more than that number, you will start to see a reduction in performance. The best thing to do is turn lights on and off, only if they will affect something within your current view frustrum. With 8 lights, you can afford some buffer zone for this too...meaning you don't neccessarily have to perform some complex frustrum testing of every wall in the room to determine if you need to keep the light behind you in the corner on. Just leave it on. If you leave the room, turn it off. You'll obviously have to be careful with this approach though.

Anything that will be lit needs a material set and normals associated with the mesh vertices.

EDIT: The previous two responses just showed up, so I'll respond to your last one. If you want to determine which lights most affect the scene, distance to each light will not be enough. You'll need to consider brightness, its effect on nearby objects (or how many objects are near it). Will it be obvious in the scene if you turn light 1 off which is way in the distance but illuminates a bowl of shiny fruit on a table, or would it be less obvious to leave that one on and turn off the light illuminating the kitchen behind the wall. Or maybe you could decide that it's worth the extra processing to leave both on...

Share this post


Link to post
Share on other sites
One other quick thing while I'm thinking about it...

Be careful of light 'popping'. If you enable/disable a light then it can be quite obvious to the player - things suddenly getting darker and so on... Worst case is if a light on the fringe of being accepted/rejected starts flickering - that is really obvious!

A better technique, and one thats best built in from the start, is a few frames of fade-in/fade-out when switching lights. It's usually less noticeable than a hard on/off.

hth
Jack

Share this post


Link to post
Share on other sites
Quote:

A better technique, and one thats best built in from the start, is a few frames of fade-in/fade-out when switching lights. It's usually less noticeable than a hard on/off.

Or you coud use multi-pass rendering (render the scene multiple times with different light's enabled) and render all of the light's that affect the frustrum using simple frustrum culling if the light count excedes 8.

Share this post


Link to post
Share on other sites
Quote:
Original post by RedDrake
Quote:

A better technique, and one thats best built in from the start, is a few frames of fade-in/fade-out when switching lights. It's usually less noticeable than a hard on/off.

Or you coud use multi-pass rendering (render the scene multiple times with different light's enabled) and render all of the light's that affect the frustrum using simple frustrum culling if the light count excedes 8.
Yup, that is a perfectly valid alternative - but it can have pretty nasty performance consequences depending on what else the graphics/application is doing. For example, the cost of re-transforming the geometry could well be painful enough [oh]

Cheers,
Jack

Share this post


Link to post
Share on other sites
Don't forget the fact that lightmaps are a very efficient technique when it comes to static lighting (indoors areas usually have somewhat static lighting in reality). They aren't very difficult to implement either, once you learn the concept of texture baking and some simple global illumination algorithms.

In addition, using lightmaps doesn't prevent you from using dynamic lights - you can freely mix the techniques where appropriate.

Finally, lightmaps are very efficient performance-wise, because the light transport is (usually) calculated before the runtime phase.

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffersYup, that is a perfectly valid alternative - but it can have pretty nasty performance consequences depending on what else the graphics/application is doing. For example, the cost of re-transforming the geometry could well be painful enough [oh]

Cheers,
Jack

True, buth he shoud only use the multi pass rendering when count of lights in frustrum excedes 8, as an backup to avoid light flicking (i think it's worth the performance sacrefice versus the horible flicking side effects). 8+ light's in a frustrum shoud not happen in a indor scene anyway ...
Besides, even if 8+ light's are in camera they are probably only affecting part of the scene (only individual objects), so not all of the object's are re-transformed.
Efficient light culling with multipass rendering can solve complex scenes, and will be 100% corect, while with limiting the max-lights/culling out the "weaker" lights the end image is not exact (it probably woud not matter that much :D)

Share this post


Link to post
Share on other sites
Quote:
Original post by Nik02
Don't forget the fact that lightmaps are a very efficient technique when it comes to static lighting (indoors areas usually have somewhat static lighting in reality). They aren't very difficult to implement either, once you learn the concept of texture baking and some simple global illumination algorithms.

Radiosity lightmaps == yummy [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!