The Road to Enlightenment?
by Shawn Hargreaves

 

 

 

 

In the beginning there was nothing.
Then God said, "Let there be light".
And there was still nothing, but now everybody could see it.


This document is in many ways a followup to my RTL lighting demo, so you should probably start by looking at that. It does smooth pixel-level lighting in a 320x200 VGA mode, but I've been thinking about various other possible approaches, and ways to do similar things in higher resolutions or with more colors. In particular I spent most of today wandering around Croydon looking for a new flat (my current lease expires next month), and in between peering at an assortment of dingy and decrepit basements that were invariably described by the landlords as "nice attractive studio flats", I had a number of programming ideas which I think are worth describing here.

What's this all about? Check out:
Note: I haven't attempted to code any of this stuff myself, so I can't promise that all these ideas are useful, or even possible for that matter, and I cannot give you example source or teach you in detail how to implement them. This is more of a brainstorming session than a proper tutorial. Someday I would like to try out a few of these techniques and see how well they work in practice, but if anyone else beats me to it, or has done similar things in the past, I would love to hear about your results...

There are basically two approaches to realtime lighting. Either the lights are part of the environment and illuminate the player sprites as they move around, or the lights are part of the gameplay (carried by players, triggered by explosions, etc) and they light up the environment. Of course you can mix both methods in a single game, but it is generally better to concentrate on one or the other. Remember that you can't have a light without some dark as well. If you have a well-lit environment to start with, there is very little point in giving your player a torch, and those lovely illuminated areas around your explosions are at best going to look rather weedy. Conversely, if you have lots of lights being triggered by actions within the game, you probably want to keep the basic level very dark to get the maximum benefit out of them.

I think that this decision really comes down to how good your artist is. From my perspective as a programmer, I cannot draw great background scenery, but I can scratch out some rough approximation of what I want, darken it down so that nobody can see how bad it really is, and then make it look quite cool by programming lots of cool explosions and missile lights over the top. But if you have a good artist, they can _draw_ areas of light, shadow, and anything else in between, and make it look much nicer than my crude programmed effects. Predrawn lights are obviously static in nature, but could be made to affect the character sprites as they move around in the game world. This approach is obviously a lot less computationally expensive than trying to light the entire display in realtime, and much easier to disable as an option for slower machines, plus it intrudes less on the gameplay: it is more of a nice finishing touch for an existing game than something fundamental to the way everything looks.

If you want to take this approach, the important thing is that the background lights (drawn by the artist) must match up exactly with the programmed lights used for the character sprites. Nothing would look worse than a character stepping out of the shadows into a floodlit area, and then the graphic only turning from black to normal colors a few pixels later :-) You will probably need a decent editing tool and a lot of patience to position all the lights correctly, and this will be much easier if you stick to soft-edged illumination rather than any really sharp bright/dark contrasts. Also consider that if your lights are all coming from static parts of the environment, you mustn't trigger any major lightsources as part of the game itself. It would look great to have a swordfight in a dungeon, with the players moving in and out of the torchlit areas, but it would look really silly if one of them then set off a grenade in the shadows, causing a huge explosion but not changing the environment lights at all...

CONTINUED ON PAGE 2 3 4 5 6