ZDoom Line Specials

212:Sector_SetColor

Name

Sector_SetColor — changes the light color in a sector.

Synopsis

Sector_SetColor (tag, r, g, b, desaturate);
Sector_SetColor (
  tag,       // Tag of affected sector
  r,         // Amount of red light
  g,         // Amount of green light
  b,         // Amount of blue light
  desaturate // How much to desaturate the palette before lighting it
);

Parameters

tag
Only sectors with this tag will have their light changed. Note that you cannot use a tag of 0 to change all the sectors in the level.
r
Amount of red light visible in the sector.
g
Amount of green light visible in the sector.
b
Amount of blue light visible in the sector.
desaturate
Amount to desaturate the palette in the sector before colored lighting is applied to it. 0 is no desaturation and 255 is full desaturation.

ACS

This special's function is the same whether you activate it on a line or use it in a script.

Remarks

Sector lighting is performed using a multiplication operation. Each palette component is converted to the range [0.0, 1.0] and then multiplied by the sector's light color to determine the final color used in that sector. As an example, considered the color [255, 128, 128] (light red). Under normal white light, this color is unchanged. To determine the color this becomes when you use Sector_SetColor, first divide each component by 255 so that it is now [1.0, 0.5, 0.5]. If you use a yellow light [255, 255, 0], the result is [255, 128, 0] which is orange (because [1.0*255, 0.5*255, 0.5*0] = [255, 128, 0]. If you use a blue light [0, 0, 255], the result is a dark blue [0, 0, 128] (because [1.0*0, 0.5*0, 0.5*255] = [0, 0, 128]). Note that even though the original color was a light red, using blue light on it turned it into a dark blue because the blue component of the original color was only at half intensity.

By using the desaturate parameter, you can add an extra step to the lighting process. If you set it to 255, the palette will be converted to shades of gray before it gets colored. A desaturate value between 0 and 255 will remove some of the color from the palette without removing the color completely, with higher values removing more color than lower values. It is important to note that the original color is desaturated before the colored lighting is applied to it.

In the blue light example cited above, if you use a desaturate value of 255, the final color will be [0, 0, 167], which is a brighter blue than what is obtained without desaturation. The formula ZDoom uses to calculate a color's intensity for purposes of desaturation is:

i 77r + 143g + 37b
65535

The result of this formula is an intensity i in the range [0.0, 1.0] that, in the case where desaturate is 255, is plugged into each component of the source color to produce a new gray color that is multiplied by the light color.

You can use the testcolor console command to set the color of all sectors that don't already have a custom color so that you can see how different colors look ingame.

Examples

The standard white light. This is the only light color Doom used:

Sector_SetColor (1, 255, 255, 255);

Red light. This removes the green and blue components of the original color so that only red is left:

Sector_SetColor (1, 255, 0, 0);

Light yellow light. The red and green components of the original color are left unchanged, and the blue component is halved:

Sector_SetColor (1, 255, 255, 128);

Shades of gray:

Sector_SetColor (1, 255, 255, 255, 255);

A washed-out look. This uses white light and a partial desaturation to make everything look grayer but not entirely colorless:

Sector_SetColor (1, 255, 255, 255, 150);

Shades of red. This is similar to red light, except the new color depends on the overall brightness of the original color and not just its red component, so it will tend to be brighter than the red light example above:

Sector_SetColor (1, 255, 0, 0, 255);

First Available In

ZDoom 1.16
ZDoom 2.1.0 added the desaturate parameter

See Also

Sector_SetFade