Ambient light

From Valve Developer Community
Revision as of 19:24, 31 December 2022 by TiberiumFusion (talk | contribs) (Revised and expanded general information on ambient light and r_radiosity)
Jump to navigation Jump to search

Ambient light, better known elsewhere as indirect diffuse light, is light that has bounced off a surface before reaching a model. Only static map lights - those compiled by VRAD - contribute ambient light. Dynamically-lit objects, including players & dynamic props, have their ambient lighting calculated at runtime, since their position varies throughout the world. $illumposition is used as the point from which all ambient light is sampled; there is no per-vertex or per-pixel indirect light technique. Statically-lit objects (static props placed in Hammer) do not move and accordingly bake their ambient light into their lightmap during map compile.

Indirect diffuse light is typically a much lesser term compared to direct diffuse light. It helps to "fill in" the dark spots and tight crevices on a model, but is not immediately obvious in most situations. Ambient light is most easily observed in a well-lit area where a predominantly white model is placed near a richly colored surface, e.g. a white egg sitting on a bright green carpet. Neither the egg nor the carpet are specular, but the underside of the egg will be tinted green as it is illuminated by light that reflects off the carpet.

Tip.pngTip:Ambient light can be created directly by configuring the Ambient property of a light_environment. It will then be emitted from skybox brush faces in all directions.

Storage

Ambient cubes. Note the reflection of light from the bright wall on the left.

Ambient terms are stored in sample points spread throughout the world. These can be visualised by enabling mat_leafvis and r_visambient. Dynamic lighting is a combination of the nearest "ambient cube" sample point and up to two direct lights.

Although their absolute number is adjusted, smaller visleaves will still have denser concentrations of sample points.

Console commands

mat_leafvis 1; r_visambient 1
These two commands together enable the display the ambient lighting sample points in the active leaf.
r_flashlightambient <int>
Seems like it would be used for making ambient light originating from projected textures or for influencing the color of the flashlight based on ambient light. Does not do anything in Half-Life 2.
r_lightcache_numambientsamples <int>
Cheat. The number of random directions to fire rays when computing ambient lighting. Default 162. Requires map restart.
Confirm:This only affects static props.
r_ambientlightingonly <bool>
Cheat. Light models with only ambient lighting; requires map restart.
r_radiosity <int>
Cheat. Selects the extent and technique used to calculate ambient lighting on entities. Modes 2 and 4 produce the most accurate lightning.
  • 0 = No ambient light
VRAD-compiled lights only contribute direct diffuse light to entities.
  • 1 = Cheap ambient light on everything
All entities receive a very rough approximation of ambient light from VRAD-compiled lights. Incoming ambient light is calculated only from the 6 cardinal directions aligned with the world's axes; that is: negative X, positive X, negative Y, positive Y, negative Z, and positive Z.
  • 2 = Slow quality ambient light on everything
All entities receive a greatly improved approximation of ambient light from VRAD-compiled lights. Incoming ambient light is calculated from r_lightcache_numambientsamples directions originating from the model's $illumposition, arranged in a sphere for equal coverage. With the default value of 162 for r_lightcache_numambientsamples, entities will typically appear brighter with r_radiosity 2 compared to r_radiosity 1. Compared to mode r_radiosity 4, this mode is better at accurately representing the indirect diffuse light received from surfaces that are extremely proximal to the model, such as the ground.
  • 3 = Slow quality ambient light on static props, cheap ambient light on everything else
Static props receive ambient light per r_radiosity 2, while everything else receives ambient light per r_radiosity 1. This is the default value for most Source games.
  • 4 = Slow quality ambient light on static props, fast quality ambient light on everything else
Static props receive ambient light per r_radiosity 2, while everything else receives ambient light from an alternate version of r_radiosity 2. Instead of firing 162 rays from the model's $illumposition until they hit a surface, r_radiosity 4 only gathers ambient light from the "ambient cubes" (as shown by mat_leafvis 1 and r_visambient 1) created by VRAD in the visleaf which the model currently is inside. Since there are often very few ambient cubes in any visleaf compared to 162 r_lightcache_numambientsamples, this mode is often faster than r_radiosity 2 while still producing a visually similar result. However, the spareness of the ambient cubes and their great variation in location will fail to accurately represent the indirect diffuse light of extremely local surfaces, such as the ground. The end result is that dark spots, tight crevices, and the underside of the model tend to receive more light than they should, reducing the contrast of the model's curvature and making it appear brighter and "flatter".
  • Values below 0 or above 4 are myths and are equivalent to r_radiosity 0.
r_ambientboost <bool>
Boosts ambient term if it is totally swamped by local lights.
r_ambientmin <float>
Threshold above which ambient cube will not boost (i.e. it's already sufficiently bright). Default 0.3.
r_ambientfraction <float>
Cheat. Fraction of direct lighting that ambient cube must be below to trigger boosting. Default 0.1.
r_ambientfactor <float>
Boost ambient cube by no more than this factor. Default 5.