Dynamic ambient light

From The DarkMod Wiki
Jump to: navigation, search


The ambient light is used to provide a base color to all visible surfaces, hereby avoiding the pitch black shadows that appear on surfaces hit by no light at all. It should 'complement the main lighting, but not be the only light of a room except in some rare cases.

In TDM, this is achieved with exactly one global light entity named ambient_world.

Having one global ambient light is good for performance, but depending on your map the player might see various locations which all should have their own lighting setup. For instance, a slightliy bluish moonlit outside, a greenly lit cellar, or a dark-red underground cave with lava pits.

To achive different looking ambients without having multiple ambient lights, there exists a zoning system. For each zone, you can set:

  • a different base ambient color,
  • a time the code waits, and a time it takes to fade to this color (to avoid abrupt color changes)
  • as well a dynamic part, which gets added to the base ambient.


While having only one global ambient light is good for performance, there is a downside: the entire visible world is colored according to the place the player is in. That means if you look from a reddish lava cave to the outside, you can also see the outside reddish tinted. This is also the case in many other games, and harder to fix than you think, especially since we do not have the source to Doom3 yet.

One common practice is to build intermidiate areas, for instance an L-shapped corridor. In this zone a neutral grey ambient is used, and so the player notices the transition less.

Dynamic Ambient Light Spawnargs

The dynamic part of the ambient light is calculated in real-time from the lights in the current zone, and optionally their distance to the player. It is then multiplied with a per-zone factor: so in a small white room the ambient has a higher influence, and is basically whitish, while in a red underground cave it has much less influence and is reddish.


The base color of the ambient light for this zone. Example: "0.06 0.03 0.03" Avoid values greater than 0.10 unless you plan on making a daylight mission.


A factor with which each light in the current zone is multiplied before being added to the ambient_light. Default is "0.01 0.01 0.01". Use for instance "0.04 0.01 0.01" for a reddish tinted ambient light. If you want to turn this feature off (but you really shouldn't, instead set ambient_light_falloff = 2 and use a sensible default), then use "0 0 0" as spawnarg.


The absolute limit for the dynamic part of the ambient light. Used to stop the ambient dynamic part overbrightening the ambient for this zone. Default is "0.1 0.1 0.1".


Default: 0 (Best looking is 1, and it has exactly the same performance as 0! So you really should use a value of 1.)

Here is an overview of how the dynamic ambient light inside a zone works. To make it more clear, only a 2D cut is shown through the room, albeit the feature works in 3D:

Ambient light dynamics.png

See also