Lighting entire levels

Started by
9 comments, last by Omid Ghavami 18 years ago
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.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
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...
Chris ByersMicrosoft DirectX MVP - 2005
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.

Niko Suni

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)
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]
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement