Updated September 22, 2007: Coming Soon. Pictures and More Example Maps Coming After Main Text
A map using some of the techniqes discussed in this tutorial can be found here. The editable version can be found here. The Hammer map file for use with the examples can be found here.
- Adding the Light Bulb
- Non-Moving Light Sources
- Adding a 'Light'
- Adding a 'Light_environment'
- Adding a 'Light_spot'
- Movable Light Sources
- Lighting Effects
- Color Theory & Psycholoy
Adding the Light Bulb
This section of the tutorial really dosen't have anything to do with actuall lighting, but making a map where the lighting magically originates from nowhere doesn't work in most cases. So, in this section I will discuss how to add a light bulb or other object that looks like it is capable of giving off light. (Though it really doesn't.)
In order to do this I will have to breifly discuss another mapping technique... adding props. If you already have a good idea of how to do this you can simply just skip this entire section, if not the answer is obvious. As I said this is an extremely breif explanation of how to add props. I will only be looking at one type of prop, 'prop_static', and then only at a few necessary options. I might discuss props in a later tutorial, depending on how fast I run out of space on this free server, so right now you can find more info at the Valve Developer Community or TWHL.
Now, to into the actuall discussion of how to add a light bulb. Overall, this is a very simple process... Place the entity using the entity placing tool, position the entity, choose the model, and set up the correct settings.
The Entity Placing Tool
The entity placing tool is a basic Hammer tool located on the left toolbar. It is the fourth button down and looks like a light bulb. (To me it looks more like a ball on a stick)
Select this tool and then look at the two drop down menus normally located in the lower left hand side of the screen. Use the lower of the two drop down menus to select the 'prop_static' entity.
Then using the 3D view simply navigate to the place where you will be placing the light, and click in the 3D view approximately where the light should be. There now will be a red box in your map. (It may not be exactly where you want it, so use the other three views to position it.)
Choosing the Model
To choose the model right click on the red box in any view except the 3D view. This will bring up a drop down menu. At the bottom of this menu choose 'Properties'.
Once you do this a dialogue box should appear. In the large white box that should take up most of the left side of the dialogue find the option titled 'World Model'. This is where we specify what the model will look like.
Now just hit the browse button and perform a filter for the word 'light'. 'models/props/de_inferno/ceiling_light.mdl' is a very nice lightbulb used in Counter-Strike: Source, and you can copy and paste the path if you don't want to search for another model.
Setting Up the Settings
Now that we have the world model we can finish making out 'prop_static' work as a lighting model. To do this find the option labeled 'Disable Shadows' and set it to 'Yes'. This will prevent the model from casting a shadow. This makes it look better, (When was the last time you saw a lightbulb that was turned on cast a shadow) and is also useful when placing the light because it will allow us to put the light entity inside the bulb. If this was set to 'No' the lighbulb would block all our light. Now we can move on to adding the entities that will actually cast the light.
Non-Moving Light Sources
Adding a 'Light'
A 'light' entity is a basic light emitting tool. It is placed using the entity placer as described above. It will cast light of a color that we specify in every direction around it, and will be represented as a lightbulb in hammer. (Though it will be invisible in the map.)
After setting up the 'light' using the entity tool and going into its properties you will notice several options which I will now discuss. They are: Name, Brightness, Brightness HDR, Appearance, Custom Appearance, Constant, Linear, Quadratic, 50% Falloff Distance, 0% falloff distance, Entit to Point At, and Maximum Distance.
This may seem like a lot for just one light, but not all of these are commonly used, and I will start by discussing the ones normally used to make a light (Name, Brightness, BrightnessHDR, and Appearance) and then give an example before I move onto the more advanced techniqes.
The name feild is used to give the light a name. This may seem useless, but it's not. It is how you can allow your light to be affected by switches or other tirggers. If you are not planning on using any triggers I would not advise giving you light a name for fun, because when you name a light it will increase the ammount of memory it will take up when playing the map. This will decrease performance. However, if you are using triggers it is best to give as many lights as possible the same name because this will take less memory than giving each light a unique name.
Note: Giving a light a name will cause a decrease in the quality of the lighting generated by this entity. (How much of a decrease depends on the map.)
The name of this option might be missleading. Not only does it set the brightness of the light; it also sets the color. If you have ever worked with colors before you'll know that they are made up of three colors Red, Green, and Blue. Each set of numbers stands for a color, except for the last which is the brightness of the light. Higher numbers make the light brighter and lower numbers have the opposite effect.
The easiest way to set the color is to click the 'Pick Color' button, you will then be presented with a color mixer that will automatically enter your color values into the box. However, if you are, for some reason, using colors that are already set, or changing several lights to the same color. You can always copy and paste the values from somewhere else.
This option is the same as the last, only it is only applied if HDR is checked during VRAD compiling. This will override the 'Brightness' value on machines with HDR turned on. This will almost always be set to exactly the same as the 'Brightness' feild and works in much the same way. Sometimes though it may be necessary to turn the brightness down due to the extra bloom effect produced by HDR lighting.
This option will change how the light will appear. (ie. Solid, Flashing, Fluorescent Twitching) This can be used for adding extra emotional and visual effects to your map. It contains several preset appearances, though it is possible to use your own using the technique explained later.
Also, one very important fact is that THIS ONLY WORKS WITH NAMED LIGHTS. If you want to add an effect to a light you must give it a name. If you don't nothing will happen.
The options are: Normal, Fluorescent Flicker, Slow Strong Pulse, Slow Pulse (Doesn't go to full dark), Gentle Pulse, Flicker Version A or B, Candle A through C, Fast Strobe, and Slow Strobe.
First, after creating the and positioing the 'light' entity in the basement set the values to this:
- 180 213 214 50
- If you read the Light Psychology section at the end of this article you'll see that this is a 'cold' light that will make the player feel more on edge. The brightness is set to 50 to make the light darker because it is just a small bulb.
- Brightness HDR
- 180 213 214 40
- I used the same values. I just decreased the brightness by 10. I did this just to emphasize my point from above about how it may be necessary to decrease the brightness. I never compiled this map in HDR format and so never tested it. Experiment with your own HDR lighting to find the right ammound to decrease it.
- I left this as it was. You can experiment by changing it and recompiling the map in Counter-Strike: Source mode. However you must remember to name the light or this will not work. Let me warn you though that the map may take a while to compile, and since it's one of the only lights in the room using a flicker or strobe-like option will really play with your eyes.
Next, select the light entity you just created. (If it's not already) Then hold SHIFT and drag the entity a short distance to the side. Now let go of the mouse button before you let go of SHIFT. There will now be an identitcal 'light' entity positioned under your mouse pointer. Simply just position this above the staircase in the basement. This is a much faster way to create lights that are similar. Manualy typing the variables would be a waste of time.
After this move on to the dining room at the top of the staircase. Create a light entity and set the variables to this:
- 233 215 171 180
- This is more of a 'warm' light. The player should feel more at ease.
- 233 215 171 150
- See above about brightness difference.
- Feel free to experiment, but don't forget to name the light.
Now, use the same copy method I described above to create identical lights in: the hallway leading to the sitting room, the sitting room, and the bathroom.
To finish move into the barn and create a 'light' entity in one of the light models. The values are:
- 244 236 202 200
- 244 236 202 150
Just copy the light again to finish adding the 'light' entities to the map. If you compile the may you may notice that the barn lighting doesn't look quite like the example map I compiled. This is because I also used some 'Light_spot' entities in the barn. This will be discussed later.
The other variables are used less often and are great for creating nice-looking lighting effects for specific purposes. These are the Custom Appearance, Constant, Linear, Quadratic, 50% falloff distance, 0% falloff distance, Entity to Point At, and Maximum Distance.
Custom appearance does the same thing as Apperance did only this allows you to specify your own change pattern. Creating a pattern is fairly simple... just use letters. Getting it just right may take a while.
When creating your pattern the letters a-z are used. (A= Full Darkness, Z=Full Brightness) Just type the letters into the box provided by Hammer. To use the Hammer example, 'aaggnnttzz' would be a steppy fade in from dark to light. While 'abcdefghijklmnopqrstuvwxyz' would be a long, gradual fade from darkness to full brightness. 'widget' would start out near bright, switch to near dark, get even darker, before getting slight brighter, then darker again, and finally getting much brighter. Experiment with your own letter combinations.
Note: As with the other appearance vairable this only will work if the light is named.
Setting Light falloff (or fade)The next three variables Constant, Linear, and Quadratic work together to change how the light fallsoff, or fades, with distance. The ratio of the three variables will determine how the light looks. This means that a ratio of 1 Constant, 0 Linear, and 0 Quadratic would be written 1:0:0 and mean 100% constant falloff, 0% Linear, and 0% Quadratic.
A tip for setting these three variables is to use ratios that can easily be converted to percents. 60:35:45 would be 60%, 35%, and 45%. Mathmatics states that ratios can be simplified and so using the values of 12:7:9 would make the light look exactly the same, but would be much more confusing to convert to percents. Also it is much easier to use a ratio like 1:0:0 for full Constant lighting just becuse it's shorter. 2:0:0 would give the same result, as would 3:0:0 all the way to 100:0:0. So just making one number bigger while setting the other two to zero will not change anything. However if the other numbers are greater than zero it will.
I cannot tell you exactly which combination works best, just experiment, but I can explain each variable and the pros and cons. This should help you decide which way to weight your ratios.
Note: VALVe has added the two variables after these three (50 & 0% falloff distance) to make this process easier. The Constant-Linear-Quadratic method will give you more control, but the percent method is simpler.
This variable helps determine how far the light will travel without changing. A higher constant ratio will result in a light that changes less over distance. While a fully constant (1:0:0) light will have no change at all over distance. This will light objects over an infinite distance with the color that you specified in the Brightness and BrightnessHDR variables. (Unless it is blocked by some object, of couse) This is useful in some circumstances, however. It can be seen from the sky and is useful for simulating starlight, sunlight (Though 'env_sun', discussed later, works better), or moonlight.
It can also be used for changing the ambient lighting of a room by allowing the light to evenly change the color of shadows in the room if it is placed correctly. (The light will be confined to the room because walls will block most of the light and there are techniques for taking care of the stray light seeping through doors) This type of lighting is also extremely useful for mood lighting.
In some circumstances the effectiveness of the moodsetting can be increased by softening or limiting the light by using the other two variables. (However you will need to keep the values less than the Constant value or else the light is not longer constant biased.)
Experiment with this lighting to find which variables work or you.
This affects how fast a light will change with distance. With this type of falloff the light will decrease at a steady rate over distance. In real life this never happens (Mathematicians say that a light with an infinite diameter would be necessary.) but it looks very nice in a video game. This is very useful for basic light sources.
Note: VALVe uses a brightness value 100 times the one you entered in the Brightness and BrightnessHDR feilds, therefore the light will start out brighter than the Constant light will.
This is set to 100% by default. Using this equation light will begin to decrease more and more as the distance increases. This describes the mathmatic behaivour of real light quite well, however in the game world it causes a fast drop off of light. To correct this VALVe had to boost the Brightness value to 10,000 times what you set before the calculations. This will make quadratic light much brighter than either of the others and also causes some problems. Sometimes a light will cause an extremely annoying and unrealistic spot of intense light to appear around the light source if it is near a ceiling. This often is so bright it hides the texture, blinds HDR players (not really that bright but close), and generally ruins the lighting effect.
If done correctly, however, this type of lighting can make realistic small lights or can be used to simulate light passing through denser-than-air substances. (Like fog or water.)
For more indepth descriptions, like equations and such or links to even more in depth info, visit the VALVe Developer Community by clicking here.
This is the persentage falloff variables that VALVe added with Episode 1. These make editing lighting much easier, but don't provide as much control as the Constant-Linear-Quadratic method does. Setting these will override the Constant, Linear, and Quadratic variables. So you do not need to change them if you are going to use this method.
Note: 50% falloff must be set for 0% falloff to work.
50% falloff distance
As its name implies this will set the distance at which the light will decrease to 50% of its brightness. The light will so halfway to this distance the light should be around 75% bright. The larger the value, the slower the falloff; the smaller the value, the faster the falloff.
Note: This variable has no effect on the 0% falloff distance. (Unlike the Constant-Linear-Quadratic method)
Note: After setting this variable and hitting apply in the entity dialogue box a resizable yellow circle will appear in the top side and front views. You can use this to size the falloff distance to exactly what you want it to be. There is even a wireframed yellow sphere that will appear around the light in the 3D view to help you visually size the distance.
Note: If you use the yellow circle method to set the variables it is extremely important that you remembet to hit the 'apply' button in the properties screen after making changes. It is possible to resize the yellow circles without going into the properties box, however this will not apply your changes. If you save your map or compile it before hitting the apply button then the changes will not be made, and the next time you load your map the values will revert back to what you had before. So, after changing the size of the yellow circles ALWAYS HIT APPLY BEFORE EXITING HAMMER OR COMPILING.
0% falloff distance
Like the last varible this will set the distance at which the light will fade into nothing. This should be set to a larger value than the 50% falloff distance. Setting this to a small value will cause a sharp dropoff in light while a larger value will cause a slower drop off rate.
Note: Setting the 50% value to a small number and the 0% to a large number will cause a fast falloff from the inital brightness then a more gradual falloff to no brightness. The opposite will have the opposite effect. This is useful for simulating different kinds of lights.
Note: Also has a yellow sizing circle, and a yellow sphere.
Entity to Point At
This is used in spotlights. It really doesn't do anything with this light. The light will point from the 'light' entity to what ever named entity you choose, but because this light emits light in all directions this makes no difference. So, overall this option isn't worth setting. (It's not even mentioned on the VALVe Developer Community website.)
This is used to limit how far the light can travel. This is mostly just useful in decreasing compiling time by preventing light from traveling forever and creating barely visible effects. It can also cut down on 'light pollution' by preventing light from seeping under doors and confining light to certain areas.
Adding a 'Light_environment'
The 'Light_environment' entity is also extremely important to a map. This entity provides the global lighting for the map. (Which is the type of lighting the sun normally provided.) Without this entity the 'outside' area of your map will be completely dark. It doesn't require any models (though an 'env_sun' works really well. This is discussed later.) but still needs to be placed using the entity placing tool.
The first thing you should do is make sure your map is surrounded by a toolsskybox skybox. After that just place your 'light_environment' entity on the map. It doesn't matter where you do this because it'll make no difference. Though later I will discuss how placing the entity in certain places can make setting some variables easier.
After placing the 'light_environment' simply set-up a few variables and your map will have global lighting that is originating from your sky. All the variables are usually used. These are: Angles, Light, Ambient, LightHDR, AmbientHDR, and Pitch.
This sets the rotation of the light emitter around the orgin. It is set up like this X-axis (pitch or up-down rotation), Y-axis (yaw or side to side rotation), and Z-axis (Roll or left-right rotation) rotation. The first and last, X-axis and Z-axis variables are not usually used. The middle one (Y-axis) however, is used to set where around the map the light shines from. 0,90,0 will move the light from hammer's 'east' to the north. 0,45,0 will move it between the two.
If you know the angle already you can just type it in here, if not there is a way you can find the angle. To to this you simply need to position the 'Light_environment' entity approximately where you want your light to originate from. (Don't worry about the hight of the entity, the pitch variable will take care of this, just worry about rotation around the orgin (0,0) in the top view. Once this is done move the camera to your 'Light_environment' entity or use the Tools>Center 3D View On Selection button, and rotate the camera so that it is looking at the Orgin. Now if you are not already in the propertys dialogue box for the 'light_environment', open it. Under the Angles variable box you should see a button. Click it, and then click the orgin. (If you can't tell where the orgin is in the 3D view you can always create some bright colored brush there temporarly.)
After this you should have a set of angles in the Angles variable box. If there are non-zero numbers in the X-axis and Z-axis spots set them to zero. (So -12, 300, 0 would become 0,300,0.) Now your light should be originating from the right place.
Note: Remember placement of the 'light_environment' will not affect anything. I just used the placement here to aid in finding the rotation angle.
This works in the same way that the Brightness variable worked for the 'light' entity. Four numbers RED GREEN BLUE BRIGHTNESS and a button to set it. Set it up in the same way.
Some variables that VALVe used for their various skyboxes can be found here.
This was not used in a 'light' entity but uses the same fromat as the variable above. What this does is changes the tint of the shadows on faces that can 'see' your sky. So if you have a house any shadows in there won't be changed, unless you have no roof or if the house is open on one side. This can be useful for making your 'outdoor' shadows look like they are reciving some reflected light from the sun, and brightens the shadows so that the map is not extremely dark where the sun is blocked.
Once again, some variables that VALVe used for their various skyboxes can be found here.
This works like the BrightnessHDR variable in the 'light' entity. You may want to set the brightness value slightly lower than the Light variable because HDR lighting tends to be brighter than non-HDR.
This works exactly like the LightHDR only it applies to the ambient lighting when the map is compiled in HDR mode.
This variable is the reason why the X-axis variable is rarely used in the Angles variable box. This sets how high the sun is in the sky. It works like this: 0 is level with the horizon, -45 is half way to high noon (I know it's strange), -90 for over head or noon, 45 his halfway below the horizon (if you wanted to know for some reason), and 90 is directly below your map.
And again, some variables that VALVe used for their various skyboxes can be found here.
Adding a 'Light_spot'
This entity is a lot like the 'Light' entity, however it doesn't emit light in all directions. It only emits light in one direction in cone shape specified by you. If you're worried that this will be as long as the first 'light' section then calm down. This is extremely like the 'light' entity. There are only three new variables (Inner Cone, Cone, and Angles) and one variable that wasn't used before but now is (Point at Entity). Other than that the variables are the same.
Note: According to the Valve Developer Community "When using this entity, it is often necessary to turn the brightness value up significantly for the effects of the light to be visible. Values of 3000-4000 are sometimes necessary for light sources like streetlights." Usually if the lights are close to the ground, though, normal brightness values should work. If your light appears extremely dim, however, this might be the problem.
Note: 'Light_spot' entities will only light things that fall into their cones. They are very useful for simulating light that comes out of lamps or other things that are conic shaped, however the will not light an entire room. This can be corrected by placing a 'light' entity near the center of the room and making it much darker than the spot lights. This will light objects outside the cone of light while making it look like all the light is being emitted by the lap or other conic object. An example of this is given at the end of this section.
As the name implies this is a cone of light. There are two cones used for 'Light_spot' calculations. An inner one and an outer one. This inner cone is where the brightest part of the light will be. Very little falloff happens in here, so it is usualy fairly small.
To set this enter a positive angle into the provided box. Then hit apply. Hammer will render the cone to help you visualize what your light will look like.
This is the outer cone. Most of the falloff will take place from the edge of the inner cone to the edge of the outer cone. The outer cone will be were the light dissappears and the illumination ends.
Set this the same way you set the Inner Cone, and hit apply. Hammer will show you another cone that approximates what your light will look like. (The cone will go through walls, but don't worry the actuall light won't.)
If you read the section on 'light_environment' this will work the same, if not then the will contain three values written like this X-axis rotation (Pitch or up-down rotation), Z-Axis Rotation (Yaw or side to side rotation), Y-axis Rotation (Pitch or left-right rotation). So 90,90,0 would rotate it half way up and a fourth of the way around.
If you know the angels just enter them an hit apply. If not you can rotate the tool in the top, left, and side views. Hammer will automatically enter the values, and you will be able to use the two cones that you set up earlier to approximate where your light will be shining.
To get into rotating mode simply select the entity then click on it once again. The four handles should change into circles. You can now rotate the entity by dragging any of these.
Point At Entity
If you don't want to use the Angles variable to set the rotation and want the light to point at something specific you'll want to use this variable. To use it simply create something and give it a name. You can do this with a brush by creating it, right clicking on it, clicking on 'Tie to Entity', and then tieing it to something. (func_wall works best)
After you have done this simply open the properties box of the 'light_spot' you are working with and select the 'Point at Entity' variable. Once this is done use the eyedropper button, located below the value box, to click on the entity. The name should appear in the box. Or you could also select the name from a drop down menu.
Now your 'light_spot' will be pointing at the entity.
Note: If the entity you point this at is parented to something and can therefore move this light will not move and will remain pointing wherever the entity started at. So DO NOT use this to track players or something like that. This is possible but this is NOT the entity to do it with. Look at the 'Npc_spot' or 'Point_spot' sections for the correct entities.
I will not be discussing these in lenght, if you want more info read the 'light' entity description.
- Name (The name says it all)
- Brightness (Color and intensity of light)
- BrightnessHDR (Color and intensity of light on HDR enabled computers. Usually needs to be a little more dim)
- Appearance (REMEMBER TO NAME BEFORE USE)
- Custom Appearance (Exactly what the name says, SEE ABOVE)
- Constant, Linear, Quadratic (Effects light falloff. Use Ratio. Percentage falloffs override values if used.)
- 50% and 0% Falloff Distances (Use distances to manipulate falloff. Can use yellow circles on map to size.)
- Maximum Distance (Sets maximum distance the light can travel before being cut off.)
Movable Light Sources
Adding a 'Light_dynamic'
A 'Light_dynamic' is a light entity that is movable in game. This means that, instead of being rendered when you compile the map in hammer, this light is rendered while the player is playing on the map. Because of this these lights take up more processing power, and are also changable. 'Light_dynamic' entities also do not have a lightmap generated when the map is comiled in Hammer. So giving a 'Light_dynamic' a name will not have the same quality decreasing effect it did with the non-movable lights.
This entity is not really one light, but instead two separate lights. (A cone model light and a spot world light.) This means that you will have to take this into consideration when setting the variables and when changing them in-game. Some of these variables affect only one light and some effect both. Variables that affect both include: Name, Angles, Parent, Target, Brightness, and Maximum Distance. Variables that affect only the Spot World Light include: Inner_cone and Cone. The Cone light only variable is the Spotlight_radius variable.
Variables that Affect Both
This the name you will use when you change variables in-game. It can be anthing you'd like. (Note: Giving two entites the same name will cause them to be grouped together. If you turn off one light; the other goes off and things like that.)
Pitch Yaw Roll
This affects what direction the light is facing when the map first starts. According to the Valve Developer Community this will only affect cone model if you use Hammer's rotation tool or if you use the Selection tool. In order to rotate the spot world light the value must be set manually... this doesn't mean that you can't use one of these methods in order to find the angles though. That's what I would suggest doing.
This is a very useful variable if you want to create something like a swinging lamp, broken streetlamp that is movable, or for any situation when you want your 'light_dynamic' to move with an object. (You do not use this, however, to make the light track something.)
Setting this is extremely simple. Just create an entity or tie a brush to an entity (a model of lamp that can be a 'prop_physics' works really well) and give that entity a name. After that just select the entite's name from the drop down menu under this variable. (Note: This works best when the parent is close to the 'light_dynamic' or if you want the 'light_dynamic' to follow something around while keeping it's orientation with the object.)
This is the variable that you will want to set if you need your light to track something while remaining in the same position. It works in the same way that parent did. Just select an entity name. (Note: If you want to create a light, like one of thoes lights that follow prisoners when the escape from prison, but don't want the light to always track the same thing you'll need to use triggers to reset the target. I have a tutorial for creating buttons and triggers.)
Unlike the brightness variables used for normal lights this is just one number between 0 and 4. 0 is dark 4 is bright, experiment to find which one works best for your map.
Like the name implies this sets the maximum distance that the light will be able to shine. Any object past this distance will not recieve light. This will keep the light from shining all the way across your map and also help to improve performance by avoiding to having to calcuate what the light would look like after that distance. (This is represented as a yellow sphere in the 3D view of hammer and a yellow circle in the other three views.)
Variables That Affect the World Spot Light
This is the same as the Inner Cone variable from the 'Light_spot' entity discussed earlier. It is the angle of the cone of brigher light emmited by the spot light, and is visible as a smaller cone in the 3D view of Hammer.
This is also the same as the Cone variable from the 'Light_spot' entity discussed earlier. It is the ange in which the light will do the most fallling off. It is reperesented as a larger cone in the 3D view of Hammer.
Variable That Affects the Cone Model Light
This is simply what the name implies. The radius of the spot light in inches (Which also hapens to be the units used in the Hammer Editor) It will appear as a white cone in your 3D view of hammer.
Under the 'Flags' tab in the proerties dialogue box you will find four check boxes. They are: No World Light, No Model Light, Add displacement Alpha, Subtract Displacement Alpha. I will only discuss two of these No World Light, and No Model Light. (the other two probably have something to do with the alpha painting tool used with displacements.)
No Model Light
As the name implies this gets rid of the cone model light. Therefore making the 'light_dynamic' only one light that will only light the 'world' or your map.
No World Light
Like the last variable, this will get rid of the world spotl light, and your light_dynamic will only light models.
Adding an 'Npc_spotlight'
Adding a 'Point_spotlight'
Adding an 'Env_sun'
Adding an 'Env_sprite'
Adding an 'Env_lightglow'
Adding Volumetric Light
Adding an 'Env_particlelight'