Difference between revisions of "Intermediate Lighting"

From Valve Developer Community
Jump to: navigation, search
m (Light Entities: Moved entities that are not intermediate to Advanced Lighting)
Line 18: Line 18:
{{note|When using this entity, it may be necessary to turn the brightness value up significantly to achieve visible results. Streetlights for example may need brightnesses of 3000-4000.}}
{{note|When using this entity, it may be necessary to turn the brightness value up significantly to achieve visible results. Streetlights for example may need brightnesses of 3000-4000.}}
An invisible light source that can change and move over time. Its position can change and it can be aimed at moving objects. Dynamic lights are recalculated continuously, which means they have a higher processing cost but are much more flexible than static lighting. Use this type of light sparingly, because it is the most expensive light for the engine to render.
{{note|This entity actually consists of two lights, a cone shape light and a spot world light.  Some values may affect one and not the other.}}
Line 37: Line 30:
Normally, only one light_environment entity is required per level. A [[3D Skybox]] requires placement of an extra light_environment within the 3D skybox. If multiple light_environment entities are placed, [[Vrad]] uses the keyvalues from the first found light_environment to calculate the lighting.{{clr}}
Normally, only one light_environment entity is required per level. A [[3D Skybox]] requires placement of an extra light_environment within the 3D skybox. If multiple light_environment entities are placed, [[Vrad]] uses the keyvalues from the first found light_environment to calculate the lighting.{{clr}}
===[[Glowing Textures|Glowing Textures]]===
[[Image:glow_selfillum.jpg|thumb|256px|right|A selfillum texture in use]]
In a few cases it’s possible to make the texture itself appear bright or even to emit light. Doing so requires the use of a .vmt or .rad file and is beyond the scope of this article. Doing so can save the mapper the effort of trying to create an even lighting affect across a surface that’s meant to be the light source.{{clr}}
[[image:int_particle.jpg|thumb|150px|right|A red light in use]]
A normal light that lights only the particles created by an [[env_smokestack]] and lights nothing else. Useful for enhancing lighting in areas with steam and such but rarely used due its specific nature.{{clr}}
===[[point_spotlight|(npc or point)_spotlight]]===
===[[point_spotlight|(npc or point)_spotlight]]===

Revision as of 18:20, 16 December 2006

Template:Int lvl design This tutorial will cover the more advanced lighting techniques used in Source maps. If you are new to lighting in Hammer, you may want to read the basic light tutorial first. To begin the tutorial all the possible ways to create light will be covered and then onto all the settings related to playing with lighting. This will then be followed by a set of more in depth mini articles on how to use and take advantage of the lighting you’ve been introduced to.

Light Entities

This is a list and rundown of each entity you can use to cast physical light. The titles for each section link to the page for the entity itself. It’s important to remember that these entities cast light in some form or another.


Example of light cast

An invisible light source. Can be turned on and off through the I/O system (note that this will increase the complexity of your lightmaps, as precompiled values must be stored for each on/off combination). Able to set up with patterns given effects but cannot move locations. Light is cast in all directions from the origin of the entity. The brightness depends upon the falloff values you set up. This light entity is the simplest and cheapest of all lights and is the most useful. Use this light whenever possible.


Light spot.gif
Example of light cast

A directional form of the light entity, its cone-shape allows for a directed form of light. Again it can be turned on and off through the I/O sytem, though a switchable light_spot may cause lightmap errors. This is a static light that can be pointed in any direction. And is also recommended for common use.

Note.png Note: When using this entity, it may be necessary to turn the brightness value up significantly to achieve visible results. Streetlights for example may need brightnesses of 3000-4000.


Light environment.png
The skybox texture
In Hammer, In Game

A directional light cast in only one direction, the direction is decided by the key values entered. The key is that the light is only cast from the tools/toolsskybox texture. The first key value, Brightness, controls direct lighting. This approximates direct sunlight. The second key value, Ambient, controls indirect lighting from the sky. This is the diffuse light that is cast on every face that can "see" the sky. Basically the shadow the light leaves.

If you don't want to come up with your own values for this entity, the values used in the official Valve games for each skybox, are given here.

Normally, only one light_environment entity is required per level. A 3D Skybox requires placement of an extra light_environment within the 3D skybox. If multiple light_environment entities are placed, Vrad uses the keyvalues from the first found light_environment to calculate the lighting.

(npc or point)_spotlight

An example in use

A straight beam of light used for a spotlight effect. The visual effects include a flare around the light source, a beam along the direction it’s pointing, and a light_dynamic where the beam touches the ground. While incapable of moving on its own, the light or its target may be tied to a moving entity. Alternately, npc_spotlight can be used to produce the same visual effect while being controlled precisely and fluently by an NPC's intelligence. This dynamic lighting source is expensive to render and should be used sparingly.

Related Items

This is a list of all the topics related to lighting itself but don't emit light. While none of these emit any physical light their all essential to creating effects with it. If it’s controlling the lighting of entities or controlling an antlion's shadow they all fall under lighting effects.

Info lighting

Info lighting.png

This is an entity used to specify the origin from which another entity is lit. Sometimes due to drastic changes in light over short distances or complex shadows a model can appear to be lit incorrectly. By using this entity the model will be lit as though it were stationed at this location.

One common example is the HL2 static Ladder props when used in dark areas they may appear to glow, which can be corrected by inserting an info_lighting, naming it and specifying that name in the properties for the Ladder prop.


the light glow effect

Used to create a bright almost flare that will fade out at specified distances. Generally used to transition dark tunnels to bright outsides. Used as a precursor to the HDR effect to fake a change in exposure of the light.


The env_sun effect

Often misinterpreted as a light that creates lighting like the sun it is instead an effect that places a flare in the sky that looks and acts like the sun. Casting no light at all it is often used with a light_environment to create its lighting affect.


Shadow control.png

Used to control all the dynamic shadows cast within the game. Shadows cast by NPC's or physics entities fall into this category. Used to line up the shadows angles so they appear correct with lighting. The one directional nature may be a problem but use of triggers to even it out should help.


An example in use

This forces a particular brush face to not receive any of the dynamic shadows created by physics entities or NPC’s. It’s used rarely but may be needed to hide incorrect or bad shadows that create an artifical look.


Used to control the exposure of the HDR lighting effects. Unless used with fully implemented HDR it has little/no effect.

Smoothing Groups

The cylinder on the left is unsmoothed.
The cylinder in the middle is smoothed with a light map of 16.
The cylinder on the right is smoothed with a light map of 8.

Used to smooth lighting between faces. Found in the face edit dialog, the groups allow the lighting of a face to be smoothed between other faces, to produce rounded effects with lighting. A classic example is when making a cylinder: If no smoothing groups are set, each face on the brush will catch light separately and will be lit separately. This will create a very obvious effect of separate each face. If they are all placed in the same smoothing group the light will be blurred between the faces creating a much smoother rounder look on the pillar. Taking no extra cost except for adding time to rad compiles they are an essential part to final lighting effects.


A lightmap is the lighting data of each face. The stored light is then added to the face giving it brightness. The lightmap's scale refers to the number of texture pixels per light pixel (luxel). Smaller values mean more luxels, thus a better quality but larger BSP size and compile times.

A lightmap scale of 4
A lightmap scale of 16
A lightmap scale of 64


It is the part of the compiling process that will generate all your lighting effects, it’s also one of the longest parts of a compile and can often be the one you need to run the most. With no way to estimate lighting effects apart from experience, it can often be tiresome to compile enough time to get a lighting effect right. The topic of how to compile Rad well is tackled later. For now familiarization with its features and setup should be a priority.


This covers how to use the mentioned items to create effective lighting. Before, a lot of practical knowledge was covered. But knowledge is useless unless it's utilized well. The next few sections are specifics about how to use all the information to create better lighting in your maps.

Color Temperature

While the RGB color of the Brightness setting of every light entity is preset to 255 255 255, very few forms of real life lighting are actually white in color. Depending on the "blackbody temperature" of the light emitted, it will emit a color somewhere between orange "red" (referred to as "warm", although its temperature is actually lower) and ultra violet "blue" (referred to as "cool"), as shown accurately on this scale. You can use this article as a reference to where on the scale your light source should end up, or you can use Valve map standards, where the RGB value for a common tungsten light bulb is a "warm" 254 216 146, a common flourescent light is a "cool" 159 237 215, and usual Combine lighting is an icy 147 226 240.

Lighting Psychology

It has been proven that cooler lighting in the "blackbody temperature" spectra (See above.) will stress percievers, making them feel uneasy and sometimes even sick, while warmer lighting will not. Certain types of light in the coolest temperature range has been outright banned from use in the states due to the effects they had on people in their environment.

This subconscious emotional response to lighting can be utilized to deliver purposely lighted environments that will set the mood of the player. It can be as simple as choosing between using flourescent lights (for horror settings) or glowing light bulbs (for safe environments).

For instance, in the first map of Half-Life 2 there is a corridor that a civil protection guard will escort the player through when he is being brought in for interrogation (or what-not). Examination of the lighting will reveal that Valve has kept the psychological effects in mind while setting it. The corridor starts off with a standard tungsten lamp (with a warm glow), directly followed by a flourescent light (with an uneasy glow). This combination is at most very rare in real life, because it would require that the architect would suddenly change his mind while designing the corridor, or the electrician running out of light fixtures. It is more likely that Valve (or the Combine) wanted to achieve the effect that one would be walking from a safe environment to an unsafe one.

In the cell before the one the player enters, he may bare witness to an unsettling scene involving a citizen explaining his predicament. Here there is a tungsten light hanging from the ceiling. This is probably because a flourescent light would clash too much with the small, cubic room. (Flourescent lights are usually used for corridors and large areas.) However, off to the side, is a disembodied light_spot, whose sole purpose is to provide the mood lighting for the scene.

Apart from the above direct effects, using color theory can also aid in setting the mood of the environment through indirect half subconscious association. Taking flourecent lights as an example, they have a cold uneasy feeling in general, so the soft unnatural blue glow can conjure up feelings of cold emptiness and isolation.

The color isn't the only effect though. The spacing and brightness of the light and what isn't lit, carries much weight too. Bright rooms feel safer because what's there is directly visible and easy to work with, but on the other hand sporadically dotted lights will amplify or create an uneasy feeling because the user has so much hidden or not quite visible to them. Along the same lines, if every corner of a room is lit except one, that corner will be percieved as holding a potential threat, or other hidden stuff, and will therefore often draw the exploring players attention.

Using this knowledge is up to the level designer. Horror maps and kids games alike can be augmented by it, and accidently creating a spooky kids game is a sure way to loose the pay check for the work. Lighting doesn't just make things be seen, it defines how they appear to everyone.

Creating a Believable Light Source

Creating a believeable light source can often be a challenge. Simply placing a light entity in a map does nothing to explain where that light came from or why it's there. A believable light source is one that appears like it should be there and sits comfortably within the environment. Often a good light is made up of multiple entities. Commonly there are two: One for the light and one for its source, often a lamp (made from a prop_static or a func_detail with an appropriate texture).

A common lamp.

The first step is to determine what light sources are available. Look for textures or models that would be emitting light. Filtering by the word "light" or "lamp" in either the model or texture browser, works well. Now pick one that fits the feel of the room (i.e. industrial lights for an industrial scene) and place that model or texture in the room. For this example pick the light shown on the right and place it with a prop_static.

Now that there's something that looks like it would emit light, the next step is to create the light it's emitting. Look at the source that has been chosen and ask yourself if the light emitted is going to be colored by tinted glass, and if the source is focusing/shading the light into a directed light source. Use the assorted light entities and set its properties accordingly to create the effect. With the given example the light is going to be focused in one direction, so pick a light_spot. Next, this is an intense light, so give it a brightness of 1000. Now look at its colour. The glass is untinted, and while the light emitted is intense, a flood light in the real world will gain its intensity through using very reflective surfaces on its inside to focus the light, so the temperature is also close enough to justify leaving the values at 255 255 255. Now line it up compared to the prop_static, and alter the angles and focus of the light so that it appears to come from the prop_static.

Now there’s a light lined up to its source, there may be a problem though. If the aligned light source has ended up inside the boundaries of the model/brush used for the source, it is going to block the light emitted (only lighting up props). To prevent this, go into the properties of the prop_static, and make sure that it has "Disable shadows" set to "Yes". (If the light source is a brush, tie it to a func_brush and alter its properties in the same way. This prevent the light from being blocked by the light source itself.

Now that you have a working setup, a good idea is to group them (and perhaps also turn this group into a prefab for insertion into other maps) so that they always stay together. Now if you need more lights, you can copy this group.

Another way to create a high quality light source that portrays real life better but doesn't compromise on performance, is combination of a light and light_spot. Position the light_spot as described above, but position the light around 50 units away from the model that is the light's source. Make this light have a brightness of approximately 50, and be the same colour as the light_spot. This will often create a more correct form of glow on surfaces that the light_spot often lacks.

Static vs. Dynamic

There are many advantages, performance wise, of using static light sources over dynamic ones. Static lights carry no additional processing weight so their use is essential to fast rendering maps. Dynamic lights can carry a lot of rendering weight and can be expensive to use in your map. Its important to know where and when to use each type of light and avoid using the wrong type.

Firstly static lights are calculated during the VRAD compile process; therefore, there is next to no calculations done in game it merely needs to render the light calculated which is a fast process. The common static lights are light, light_spot and light_environment but there are conditions that can change this. The problem which comes with static lights is the fact that it is static. While they allow very precise and detailed lighting no special effects can be given with static lighting because it’s not going to change.

Dynamic lighting on the other hand comes in two flavors. There are the switchable lights and the true dynamically calculated lights. Each has its own processing weight but both are expensive to render and should be used sparingly.

Switchable lights are the same as static lights in that they use lightmap information compiled during RAD. A light is set as being switchable by one of three things such as giving it a name, giving it a style, or giving it a pattern. Regular lights that don't support dynamic effects are the lights generally used as switchable lights, this includes lights like light, and light_spot but not light_environment. Switchable lights use a set of two lightmaps on and off. Switchable lights alternate or blend between the two lightmaps, this allows partial brightness while keeping it to just two lightmaps. This gives all the benefits of the static lighting but allows it to change and be partially dynamic. Say you have two switchable lights shining on the same face, how many lightmaps are needed?

  • Light 1 & 2 ON
  • Light 1 ON, 2 OFF
  • Light 1 OFF, 2 ON
  • Light 1 & 2 OFF

That's four states in total. You add a third switchable light and it goes up to eight lightmaps. Here becomes the problem with switchable lights, it becomes expensive in lightmaps to create all the possible states. So expensive in fact that there is a hardcoded limit that means you can only have two switchable lights affecting the same face. There is a slight solution though, the lights with identical names will all be given the same lightmap, so you can have 50 switchable lights with the same name shining on the same face; however, you cannot have more than 32 light source names. . Because of the extra lightmaps switchable lights use it increases the amount of time it takes RAD to run, increases file size, and also uses up system resources when it alternates between them; however, a switchable light sat in one state or the other, has little or no more effect than a static light.

True dynamic lighting is something that has to be built into the entity itself, its most often recognized by the Parent property within the entity. The entities with the built in dynamic effect are light_dynamic and point_spot. Point_spot is special in the unique fact that is has a flag that can enable it as dynamic or static, its set to dynamic by default and can often catch you off guard. The dynamic process done for dynamic lights is run entirely within the game, this means it has little to no effect on the RAD compile or file size but it will slow down your map. The system slowdown caused by dynamic lights is generally consistent as the light needs to be rendered continuously. Such entities should only be used when the source of the light is moving, if the light itself is not meant to move then it shouldn't be a true dynamic light. If it’s merely meant to turn on and off it should be switchable. No movement should be static. If used improperly the costs of using dynamic lighting will outweigh the benefits of doing so. Dynamic lights should be used even more sparingly than switchable lights. Another down side to the dynamic light is that to simplify the calculations it doesn’t run process like reflection and diffusion, this results in harsher simpler looking lights.

Static lights are easy on the engine and give great detail, but dynamic lights represent the possibility for movement and change, but cost a greater amount to render and loose detail. The easiest way to tell what effect the dynamic lights are having is to test your map with the +Showbudget command. This allows you to figure out when an effect is too much and lighting effects are slowing down your map. Good use of dynamic lights can only improve your map, but they can be a costly effect.

Lightmap optimisation

Lightmaps store nearly all the lighting information in Source BSPs, and their efficient use equates directly to efficient lighting. They are the key contributor to BSP file size: efficient usage is a must for anyone wanting their map to be downloaded off the cuff, and preferable for everybody.

Lightmap scale is the basic component of optimisation. It determines how detailed lighting information will be for a given face (you can see the effects above). The more information stored, the bigger the file size. Small lightmap scales allow for fine details but come at the cost of a bigger file (performance is unchanged). Large lightmap scales create fuzzier lighting but lead to smaller files. Determining when a face needs a detailed lightmap and when it doesn't is therefore the task.

This can mostly be done by eye from a compiled map. Look for the faces that receive high contrast shadows or specific details, as they are often the best candidates for low (i.e. detailed) lightmap scales. Faces with slow blends or lighting that only slightly differs across them on the other hand can safely have their scale raised.

Note.png Note: Remember to take into account the size of a face, too. Moving a large face even one point up or down can have very large effects. Don't be afraid to split the face into segments if you need to.


A working example.

For a working example look to the hallway shown on the right. One side shows the in-game compiled version and the other side shows the lightmaps as displayed in Hammer. The lightmap view is easy to access: left click on the word Camera in the top left of your 3D view, and from the drop down select 3D Lightmap Grid. In this view, yellow faces have smaller than default scales, white faces are at the default, and blue are larger.

The hallway we are looking at has wall mounted lights and a few ceiling lights as well. In the picture it's clear to see where the lightmap scale has been increased and decreased. The front of the pillar has an increased lightmap because of the light source on its face, to catch all the detail. This is not such a major problem as the pillar is a small thin face and the only area with a lower scale. The floor and a few of the walls along the edge have been scaled up, as looking at the in-game rendering little to no detail or change is seen in the lightmap; they are excellent candidates, the floor especially so with its large size. The other faces have been left at the default resolution as they all have some play of shadows or changes in brightness. While not detailed or essential enough to warrant a smaller scale, increasing the scale would only serve to create poor looking lighting as the lack of detail would show.

While technically possible to decrease the entire scales across the entire map for crisp shadows, the compile time and filesize expense almost always outweighs the benefit. Finding the balance between increasing and decreasing the lightmaps may take a few lighting compiles and some guesswork, but performed correctly can both enhance your map and reduce its filesize.

Quick and Effective RAD

The fastest way to compile RAD is to avoid compiling as much of it as possible until it becomes necessary. While working on a map the best approach is to not compile the entire map at once and to not compile every time new lights are added. If the map is constantly recompiled just to find out what changes a couple of new lights made all progress will slow to a crawl. Essentially the trick is to compile less data fewer times, but also learning when and how to get away with it. The easiest way to compile less data is to isolate the area the lighting effects are being created in and forget the rest of the map. This is what the Cordon tool is designed for, sectioning off parts of the map, its one of the best ways to speed up compile times. When creating a new room always cordon it off before beginning the lighting process, the room is the only new item and should be the only room being compiled, but don't be too stingy. Light may leak from other rooms and is an important consideration. Truly faster compiles only come from less surface area or less detail, the only other option is a quick compile. A quick compile can show roughly how well lit an area is without spending twice as long doing it. Generally full compiles will produce a slightly brighter ambient and smoother shadowing, they look prettier but do not do much to change the overall brightness except increasing it slightly, quick compiles only directly light faces and don't take into account diffusion and reflection aswell as other effects. The best approach to compiling less often is to determine necessity, if the purpose of the compile is to test if the NPC does his script properly theres no need to compile lighting as it does not affect the NPC. Another way to compile less is to standardize the lighting in the map, if the lights are the same its already known how they light a room and it is not necessary to compile the map to judge the lights effects. The first step is to create light sources; models, lights and effects that combine to create 1 reusable grouped lighting effect. Every time that type of light, paste a new version of that light in your map. Its already known what lighting effects it will produce so theres no longer a need to compile the lighting in that section to guage how well lit it is. With at least 5 light types and strategical placement an entire map can be properly and well lit on the first full RAD compile.


This covers the base of all lighting effects that can be found in standard Source games. New lighting effects may be added with the release of Episode Two.

To do: Create nav bar.