Tutorial #6: "I have seen the Light!!"               by Hellbringer


   (*Note:  This tutorial assumes you have both Half-Life AND
 Worldcraft v2.0.  This tutorial is designed for those of you
  who have AT LEAST had experience with maps in my
                 earlier tutorials. 

 WARNING: This tutorial is NOT for the faint of heart! The
 map is fairly complex; so if you're not familiar with
 everything that's been covered in my previous tutorials, you
 may be a little overwhelmed. Remember to start small and
 build up in complexity; it will save you a lot of frustration in
 the end! If you have any questions or problems as a result of
 this thing, definitely email me and I'll try to help clear the
 confusion.  
                            
                    This tutorial covers:
                      The Light Entity 
                      The Light_spot Entity 
                      The Light_environment Entity 
                      Volumetric lighting effects 
                      Texture-Lighting vs. Point-source
                      lighting 
                      A ton of other small things that you
                      can pick up on from poking around
                      in the map file. 


 Welcome to the light tutorial - this one's gonna be pretty hefty; and I'm going to be pretty
      brief. 

 FIRST, grab the light1.zip file here.  This contains the .rmf file and a Text file version of this
    document. 

                 Unzip this into your maps directory under WorldCraft. 

   This walkthrough assumes you have compiled in "Expert" compile mode, and have run
        QRAD AFTER VIS. My Compile FAQ can step you through how to do this. 

  Lastly, if you are comfortable with adding parameters to the compile process; I suggest
 adding "-smooth 80" to the QRAD parameters. This is just to add a nice blended touch on
                certain angled edges; and is NOT crucial for this tutorial.

   I'll walk you through the level here, and point out the highlights and reasoning behind
 things; and I STRONGLY SUGGEST YOU COMPILE AND WALK THROUGH THE MAP
 BEFORE toying with the .rmf file. Also, you'd best make a BACKUP COPY of the .rmf file
 in case you get into trouble with it, or want to go back and look at the way I did things
 originally. After I'm through explaining, feel free to toy around with the .rmf file and take any
 IDEAS you have to your own levels; PLEASE do NOT copy my work straight over to your
 own level... You should be able to come up with your own ways of doing things; and you can
 always ask me if you run into trouble. Also, nearly every detailed piece of furniture or item
 in this map was taken from the prefabs that came WITH WorldCraft, so you can find
 those and make those very easily on your own. 

 As a final note, I want to explain that some portions of this map were done DELIBERATELY
 in a less-than-optimal way to show you quirks or problems with the way the game engine
    works. Now, on with the Walkthrough! Load up WorldCraft and compile the .rmf file 

   We start off the level in a small outdoors area. I'm not going to explain HOW I made
 brushes and things the way they are - most of it was done "on the fly" (not good for actual level
 design; you should always have a clear theme and plan thought out ahead of time, and at
 least sketch out the basics on paper).  The MAIN thing I want you to note is how the sky is
 casting shadows of the buildings and objects around here. This is because of the hidden
 "light_environment" entity. You only have one of these per level (but you must manually place
 it), and it defines the "angle" of any sunlight that emanates from Sky textures. You set a few
 keys similar to a standard light entity, and then set the "angle" and "pitch". Angle works like
 with any other entity; and you can use the "compass" in the properties box to see where a
 specific angle points, relative to the top down (XY) view. This is good for adjusting what
 direction (North, South, East, West, or somewhere inbetween) the sunlight is shining towards.
 Then you set the "pitch" key. Pitch is like angle; but for the vertical axis. "0" = straight across,
 "-90" = straight down, and "90" = straight up. You can have any value between "90" and "-90"
 that you like. In this level, I set the "angle" to "305" (pointing South-Southeast), and a "pitch" of
 "-80". Thus you get a small amount of shadow cast from the buildings and such... NEVER
 underestimate the affect that good combinations of light and shadow can have on an area!
 Here's a pair of shots showing these shadows off (I was going for a subtle shadow effect): 




   Now, if we bump into the door, it'll swing open for us... so let's step inside shall we?
 (NOTE: For realism, I made the doors swing one way only; so they look like they're
 on one hinge. This means that sometimes you need to back up a little to let the door
 swing open. Its not the perfect solution; but it works for this tutorial) This first area is
 an example of a standard point-source light (there is a "light" entity hovering just below the
 fluorescent fixture). It doesn't have any special effects, but notice how it still casts light through
 the "window" into the office? Lighting is based on visibility in Quake-engine games (which
 Half-Life is based on); so if the game engine thinks the player might be able to see from the
 light-source TO someplace; it will calculate the light falling on that place. This is an important
 concept; as we're about to discover... Here's a small double-shot of this area: 




   That darkened office looks interesting; so let's step in there. BEFORE you hit that inviting
 light-switch, walk over to the desk. I want to explain this lamp first. This is a prefab from
 WorldCraft that I modified and re-textured. It is actually made of 4 parts. The base and metal
 holder are standard brushes. The green lamp is actually a dark green glass texture and is a
 func_wall entity JUST LIKE our other glass objects in the level - but I've made it much less
 transparent. (You can see this when you go into WorldCraft in the "FX Amount" keys. Look at
 the difference in the 3 glass objects you've seen so far when you do this.) The last two parts of
 the lamp are both "light" entities. The first one is a "light_spot" entity, and is aimed to cast
 light on the desk. The second one is a "light" entity; and is placed to cast light on the lamp and
 surrounding areas very dimly. Why do this?? Well, the fact of the matter is, "light_spot" entities
 are very "focused". They cast light FROM one place, TO another. There is no scattering or
 bouncing of the light near the source; so if we didn't have this second "light" entity, The lamp
 itself wouldn't appear to be lit up at all! You would just see a dark lamp and a spot of light on
 the desk - how weird would THAT be??? Here's that lamp: 



   Now turn around, and walk back over to the door we came through. If its open, CLOSE it.
 Notice something??? There's a spot of light on the wall!! Where's it coming from?? The actual
 answer to this question comes from my previous explanation. You see - since the engine
 never knows if a door will be open or closed, it assumes that doors can't block visibility. This
 is IMPORTANT to remember!! Since our light is calculated on visibility, light isn't blocked by
 doors! So this light is actually "bleed-through" from the hallway we were just in. (I know, it
 seems like a stupid thing to not be able to predict; and its highly unrealistic; but it is a complex
 and odd quirk of the game engine and compile tools that can't be solved easily - its been
 there since Quake 1/2 actually.) This is what that unfortunate quirk produces: 



   NOW, feel free to hit the light switch. It is just a button with an animated texture on it (you'll
 see some special leading characters in WorldCraft that denote this. Look at any button-like
 texture that has a "lit" and "unlit" version, and you'll see what I mean). This button is also set
 with the flag "don't move". It targets a point-source light (a "light" entity) just below the
 fluorescent light on the ceiling. The light entity in this room has the flag "Initially dark" set; and
 is named so that the button can target it. When the button is pressed, the lights come on.
 Simple concept; and hopefully simple to get to work for you. The button and light: 




   Let's get out of this office; and on to the next section of hallway. I don't want to stay here, as
 the flickering drives my eyes batty; but suffice it to say that this is a point-source light (again, a
 "light" entity) just below the fluorescent fixture. I have set its "appearance" key this time to
 "fluorescent flicker". In every other respect, it is like the first hallway's light entity. (Note: these
 effects are called "dynamic lighting". They can slow framerate a tad bit. See the "Extra
 Credit" section, item #5). Here's a shot of it flick-flick-flickering: 




   The lounge here is probably the single best-looking area in the entire mini-map. The
 REASON for this (behind lots of prefabs to give a detailed area), is that I used
 TEXTURE-LIGHTING here. This is a VERY VERY IMPORTANT thing to learn. But before I
 explain texture-lighting; notice some pink/red light scattered about the room??? This is
 radiosity lighting at its finest!! If you run QRAD after VIS, you'll see this effect better, but
 radiosity lighting is the technique of bouncing light off of things - you see, "direct" lighting just
 simulates casting light from the source to an object, and either brightens or dims that object.
 Radiosity lighting, on the other hand, is the technique of "scattering" the light and simulating it
 not only hitting a object, but bouncing OFF of that object, acquiring a little color of that object,
 and continuing to do this several times before it "dies" out. This is similar to the way in which
 real light particles work. So this "pink" we're seeing is light bouncing off of the Soda-pop
 machine; even though it is not a light itself! It lends a LOT of atmosphere to the room, even
 though it is a subtle effect. Here's a shot: 

        (Caption reads: Yellow outlines the areas where color is being reflected)


   Now to explain Texture-lighting: 
  Texture lighting is the technique of taking a light color from a texture; and simulating light
 coming FROM that texture and scattering around an area. There is a file called "lights.rad"
 that QRAD uses. This text file defines which textures give off light, how much light, and what
 color the light is that they emit. NOTE: This light effect will be applied AUTOMATICALLY to
 ANY object in the game that uses a texture in the "lights.rad" file - so if you want some
 objects with that texture UN-lit; you cannot use texture-lighting; and must stick to
 point-source lighting (i.e. "light" entities and textures NOT in the lights.rad file). Luckily for
 us, there are several different fluorescent light textures that LOOK similar; but some of them
 aren't defined in "lights.rad" to give off light. I used THOSE textures for the lights in previous
 hallways (with point-source lights), and used the textures defined in "lights.rad" for the
 fluorescent fixtures in THIS room and in the next hallway. Here's another shot of that pretty,
 pretty effect: 



   Moving on, we come to (surprise!) another hallway. I know that the red light at the end is
 enticing; but let's build the suspense and go into the first room on our left. (BTW, this hallway
 uses copies of the lights found in the "lounge" area.) If you open the first door on the left and
 look in, you should notice 3 things. 
  First: There is no light fixture in here. This looks odd in a "real" level. Light is coming from a
 "light" entity that I have positioned somewhat close to the ceiling (you should be able to see a
 brighter area on the ceiling where the light is closest to). 
  Second: There is a crack in the roof; and I've put in a "func_illusionary" brush with its
 contents set to "volumetric light". This is actually a buggy entity; which I'll get into in a
 moment... but it SHOULD look somewhat like a shaft of light shining down from the "hole in
 the roof". 
  Third: The "hole in the roof" IS a hole I carved out of the ceiling brush, and then I capped it off
 with a sky-textured brush so there wouldn't be a leak in our level here - BUT the "volumetric
 light" func_illusionary brush appears to be stopping any light from shining through it
 (remember we set the "light_environment up earlier, so light SHOULD shine through from the
 sky-textured brush and cast a shadow on the floor). 
  Here's how it looks: 



   Time to explain the various drawbacks of the "volumetric light" effect. I say NOW that this
 effect should be used VERY sparingly; and I would recommend that it NEVER be used in a
 place where the player can get to it. The reason is that this effect is treated like water. In fact,
 if you have the patience, you can actually move the player into this entity and swim around in
 it!! Also, you can drown inside of it! In addition to all of this - as I mentioned, it appears to be
 blocking the light and shadow from the sky texture as well. Pretty much every key that I set up
 for this entity is required; so look at it in WorldCraft to see how I did this. Just for kicks, this is
 a pic of the player "swimming" up in the "func_illusionary" brush: 



   When you're done here, let's go check out the last area of this map. WARNING: This last
 room is EXTREMELY COMPLEX!! I could've made just the pulsing light; but I went all out
 to: a) Show off the possibilities, and b) My artistic sense took over; I couldn't have a
 "disaster"-type light without making up a little disaster, complete with scorch marks, blood,
 and dead body (Yes, I know its weird how the two "accidents" are on opposite sides of the
 room; but it was just for kicks). ALL THESE THINGS I -WILL NOT- explain here, simply
 because it would take too much space; and it is something for you all to build up TO some
 day; but not do right off the bat. Even -I- created things one step at a time - all over the
 course of a couple of hours... its not something you should try to do all at once. Please do
 NOT e-mail me asking "hey, how did you do that disaster stuff in the lights tutorial"... This
 was eye-candy; and the tutorial is on lights. Feel free to experiment on your own with these
 things later. 

    Okay, now that THAT is said and done, let's have a look-see at what makes up the lights
 in this last room. We'll start simple: There is a point-source light ("light" entity) that is just
 below our spinning brush. This is set to emit red light and the "appearance" key is set to pulse
 slowly. 
 Next, there is a fairly dim "normal" light entity next to each of the north, south, east, and west
 faces of our spinning brush. This is because the Pulsing light entity doesn't cast light on these
 faces (remember, point-source light emanates in a sphere out from the center of the entity - so
 if you look at the objects in WorldCraft and imagine straight lines in all directions radiating
 from the center of the light entity, you'll see that none strike the "sides" of our spinning brush) .
 Without these extra lights, the four faces of the spinning brush would be completely dark.
 Here's a couple of quick shots to illustrate the point: 

      

   Lastly, there are four brushes that are cone-shaped, and have the "fade" texture applied to
 them. I then selected them all at once, and converted them to a single entity (more on that in a
 moment). I set the "Render mode" to "additive", and the "FX Amount" to a really low number,
 so that they would be almost completely transparent. I also set the face textures on the "end"
 of each light-cone to "black", because black becomes completely transparent when the
 render mode is "additive". 
  To complete the effect, I added an origin brush and combined it with the four "light cone"
 brushes to make a "func_rotating" entity. This entity is for fans and other objects that rotate
 non-stop. I set the "speed" key a little slower than the default, and was done with it. 
  So the "light-cone" brushes were now rotating, but I needed to make the actual brush with the
 "red light" textures spin as well. I added a second origin brush (both origin brushes are
 aligned with the center-point of the "red light"-textured brush, so that everything will appear to
 rotate around the same point), and converted it and the "red-light"-textured brush into a
 "func_rotating" entity as well. I set this entity to have the same rotation speed as the
 "light-cone" brushes; and was done! (I made them two separate entities, by the way, so I
 could apply the "render mode" and "FX Amount" settings to the light-cones without affecting
 the spinning brush's "render mode" or "FX Amount" settings). The completed effect looks like
 this: 



   Well, that about covers every type of light you can have in the game. Remember that
 "pulsing" and "flickering" are just two of the many "light" entity effects you can choose from in
 the "appearance" key, and feel free to poke around the map to look at how I made the glass,
 decals, see-through fence and stairs, sky, and other things. 

   Extra Credit: If you understand everything to this point, here are a few more tips/issues to
 notice within this level: 

   1) Door edges when they swing open may be dark/black. This is related to the light issue I
 illustrated before, where no lights in the area shine upon a face of a brush at a particular
 angle. Most quake-engine games have a way to set a "minimum" or "ambient" light value, so
 that no texture like these are COMPLETELY dark; but I have yet to nail this down in Half-Life
 for sure. I didn't want to post information in the main tutorial if I wasn't sure about how to get it
 to work. 

   2) You can "break" the door that goes from the outside to the inside temporarily. To
 synchronize the movement of the door and the glass, I have a pair of triggers on either side of
 the door that target both entities. If you trigger both and then attempt to re-trigger them (i.e.
 Walk back through the doorway) too quickly, the triggers won't have had time to reset. Its a
 small detail; but since the focus wasn't on doors, I didn't take the time to perfect the reset-time
 settings. I still recommend using a "multi_manager" entity for this sort of thing where one
 trigger targets multiple objects; but I didn't have the time to put one in. 

   3) Some chairs are moveable and some aren't. This is related to the fact that I modified
 them from the prefab; and rotated/re-aligned them some. I did this because I didn't want
 EVERY object in the "lounge" to be at a 90 degree angle to everything else... small
 mis-alignments with objects like chairs and tables go a long way towards things subtly looking
 more real. Have fun with the pushable chairs... zing them around the level! 

   4) I know I mentioned the "lights.rad" file up above, but there is a command line option
 "-lights [file]" that lets you use a custom ".rad" file of your own. Simply make a file up with the
 same format as "lights.rad", but ONLY include the textures you want to be lit as
 "texture-lighting". Then, make sure you run QRAD with the "-lights [file]" as part of the
 parameters before the map name (replace the "[file]" with the name of your ".rad" file). This
 overrides using "lights.rad", and QRAD will use YOUR file INSTEAD. 

   5) One note on the pulsing/flickering lights: These are dynamically calculated while you play
 the game, so they take a toll on the processor! I would advise against using many of them in
 your maps; and do so in areas that do not experience lots of combat or high-detail!! 

   6) Related to the chair issue: Objects are not re-lit if they move from a static-lit area to a
 dynamically-lit area (i.e. from a place where the lights are "set" to an area where lights turn on
 or off, or pulse/flicker/change). It takes some effort; but if you can pull out 2 of the chairs from
 around the lounge table, one of them fits down the hallway (the other moveable one doesn't).
 Try and shove it into the room with the red light and you'll notice this fact quite clearly. 



    Hope you enjoyed this little map, I know I had fun putting it together; and I hope you have a
 clearer understanding now of how lighting works in Half-Life... Good luck, and Happy editing!! 

  As always, feel free to email me any comments, questions, or problems!

E-mail Hellbringer:	noelwade@hotmail.com

