Knowledge Base - Colored Lighting

Colored Lighting


Colored Lighting
Figure 1: Colored Lighting in Action

Colored lighting is an nice ambient feature in ZDoom and when used with care, can really enhance the atmosphere of a level. The implementation is very effective in ZDoom and easy to use. The example wad, testcol.wad illustrates the concepts in this tutorial.

Map Setup
Figure 2: Map Setup in WadAuthor

Figure 2 shows the map setup in WadAuthor. The sectors marked with Sector Tag will each have a separate color. The map has a switch that will be used to switch the color for the main sector from white to gold as is illustrated in Figure 1. Each sector that will have a different color will have to have a different sector tag.

If you load the wad, you will notice that there is a hesitation when the game starts. This delay is the engine building color tables for the different colored sectors. This delay is incurred each time a new color is added to the map, so it is recommended that dummy sectors be used to "hold" the color until it is used in the map. This is what I have done for the switch so that when the player switches on the color, it is changed immediately. The dummy sector light value is already set to gold at map start up and so the engine already has that color in its color table and will just change the sector's color without rebuilding the color table.

Script Editor
Figure 3: WadAuthor Script Editor

The best way to set up all the colors is to execute a script at the start of the level. This is done via an OPEN script shown in Figure 3. Each script must have a unique number and the keyword OPEN means to execute this script when the level starts. In this case, the Sector_SetColor commands will be executed, setting the tagged sectors light color to the indicated RGB values.

To invoke the script editor, right-click on an un-used portion of the map in WadAuthor and select Scripts from the pop-up menu. If you are using a different editor, you can create the script in notepad or other text editor, compile the script using the ACC compiler and then adding the script to the wad using Wintex or another wad tool.

This is what Marisa says about the SCRIPTS and BEHAVIOR lumps:

The only lump ZDoom cares about is BEHAVIOR. SCRIPTS is generated by WadAuthor for your convenience and contains the source code for the map's scripts. Without the SCRIPTS lump, WadAuthor would have to decompile the BEHAVIOR lump, and unfortunately, because it only knows about Hexen, it would fail if you used anything ZDoom-specific in your scripts.

A script must begin with { and end with }. All the commands must end in a semicolon. You will notice that ACS looks a lot like C. However, it is a much simplified version and even non-programmers will be able to build complex scripts with practice. After entering your script in the editor be sure to compile the script and then save the wad. Scripting will be illustrated fully in another tutorial.

The Sector_SetColor command is used to change a sector's color:

Sector_SetColor tag, RRR, GGG, BBB

  • tag: This is a unique number that identifies the sector.
  • RRR: This is the red component of the color.
  • GGG: This is the green component of the color.
  • BBB: This is the blue component of the color.

The following command will set sector 1 to a red color:

Sector_SetColor (const:1, 139, 37, 0);

The sector setcolor command can also be tied to a linedef to dynamically change a sector's color. This is useful for switches or walkover lines. Figure 4 illustrates the switch setup in the example wad using WadAuthor.

SetColor Setup
Figure 4: SetColor Setup in WadAuthor

The Sector_Setcolor command takes the same parameters as in the script call. The first parameter is the sector tag, the last three indicate the RGB color value. In the example, the switch is marked as "Player Uses" and "Repeatable". Once the player uses the switch, the color of the sector will change to gold.

Colored lighting is handled the same as regular lighting in ZDoom. That is, you can use all the light specials with colored lighting. You can also do all the common special effects like gradient lighting using multiple sectors with different light levels.

It is easy to get carried away with colored lighting. However, in my opinion, if used carefully (strobing red warning lights, for example), the level designer can really enhance the atmosphere and ambience of a level.

Sources

ZDoom reference by Marisa Heit.
3D Game Alchemy by Steve Benner, et al. Copyright © 1996 By Sams Publishing

Back