Lighting for Games We can all agree that video games have made enormous strides in their relatively short lifespan. In the old days, games like Pong, Asteroids, and Pac Man relied on a single color image restricted to an environment the size of the game's screen. There was no color, lighting, or shading, and the games were created more by programmers than by artists. As more expressive games like Donkey Kong, DigDug, and Galaga came along, they introduced color to their environments in the form of sprites. Any apparent shading or shadows were separate sprites and had nothing to do with an actual lighting model.Today's games present an immersive, detailed 3D environment, complete with shading applied to hundreds of objects, as well as lights that interact with, or at least appear to interact with, those objects. Even the jump in visual quality from the original Doom to the new Doom3 is impressive by any standard, and much of this is due to the improvements in how lighting is handled.When approaching a lighting project for a video game or game level, several key pieces of information must be gathered and decisions must be made. What game engine will be used and what are its lighting requirements? Can lights be animated (intensity, orientation, and so on), or should you use animated sprites or materials instead? Finally, what is the look and feel that your game is attempting to convey? In terms of lighting art direction, the game may have an established style that must be taken into account. Doom and Resident Evil, to take just two examples, have a relatively long history, and their lighting schemes have consistently been dark and foreboding. On the other hand, the veteran racing game Gran Turismo has used a variety of different lighting scenarios, so players will not come to the game with a fixed idea of what the game's lighting will look like. Having a clear goal at the beginning of the project will make sure your scene fits seamlessly into the final product.Tip | New to 3ds max 7 is the ability to use the mental ray rendering option with the Render To Texture feature. In previous versions, only the Default Scanline Renderer could be used for this. |
Key Lighting As with any lighting scheme, it's best to start with the key light. Let's place the basic key, focusing on the main elements in the scene.
1. | Open the file Giant_01.max from the DVD. This very nice model is available courtesy of Sami Sorjonen, s-s@sci.fi, www.cgmill.com/ss. Its face count has been reduced for this exercise. | 2. | There are currently no lights available in the scene and very basic materials applied. Ensure that the camera_shot1 viewport is active; then render the scene (Figure 13.22).Figure 13.22. The starting point for this exercise.
Note that the scene renders in square patches in the Rendered Frame Window, rather than from top to bottom as you might expect from the Default Scanline Renderer. This is because mental ray is the renderer assigned to the scene, and this render pattern is a feature of mental ray called bucket rendering. Bucket rendering renders groups of nearby pixels rather than horizontal scanlines.Our subject, the giant, is surrounded by some type of organic structure while he remains fixated on the crystal floating overhead. With only the default lighting available, the scene looks flat and unappealing. We'll start by adding a key light to bring the focus to the giant. | 3. | In the Top viewport, create a target spotlight to the left of the camera. Drag and release to place the target centered on the giant (Figure 13.23).Figure 13.23. Place a spotlight in the scene as the key light. [View full size image] | 4. | In the Left and camera_shot1 viewports, raise the light so that it is slightly higher than the character's head and place the target even with his hips. | 5. | Select the Spotlight. In the Modify panel's General Parameters rollout, enable Shadows and choose mental ray Shadow Map from the drop-down list. With mental ray as the renderer, we can take advantage of the speed and quality of the shadows that are specific to mental ray. | 6. | In the Intensity/Color/Attenuation rollout, check the Use check box for Far Attenuation. Set the Start value to 275 and the End value to 900 to force the light to decrease nicely as it passes through the scene. | 7. | In the Spotlight Parameters rollout, decrease the hotspot until it just barely encompasses the giant. Set the Falloff value to roughly twice the Hotspot value. The large variance between the hotspot and the falloff will give the shadows a nice soft edge (Figure 13.24).Figure 13.24. Set the spotlight's parameters to focus on the giant and to create soft shadows.
 | 8. | Rename this light Light_Key; then render the scene (Figure 13.25).Figure 13.25. The scene after the key light has been placed and adjusted.
 |
Fill and Special Lights Now that the key light is in place, we need to illuminate the opposite side of our character. We'll create a new light to fill in the areas that still remain too dark. Then we'll address some special lighting needs.
1. | In the Top viewport, select Light_Key. Hold down the Shift key, then drag the light to the right and slightly behind the character. In the Clone Options dialog, choose Copy and rename the light Light_Fill. The new light's placement should be similar to what you see in Figure 13.26.Figure 13.26. Clone the key light to create the fill light. [View full size image] | 2. | In the Left viewport, move the fill light downward until it is just above the floor; then move the target until it's even with the middle of the character's chest. | 3. | Leave the light's parameters as they are for now. You won't be able to see the effect of the fill light from the camera_shot1 viewport, so activate the Cam Close viewport and render the scene (Figure 13.27).Figure 13.27. With the addition of the fill light, the back of the character's head gains some illumination.
The two-light configuration that we currently have is easily manageable. A scene with many lights quickly becomes unwieldy as you try to select and adjust each light. Luckily, 3ds max has a toolthe Light Listerthat makes adjusting the most common light parameters a great deal easier. | 4. | Open the Tools menu from the menu bar, and choose Light Lister. The Light Lister dialog will open, showing a list of all the lights in the scene as well as the most commonly adjusted parameters (Figure 13.28).Figure 13.28. The Light Lister, showing many of the commonly adjusted parameters of a scene's lights. [View full size image] Tip | When two or more lights are instances, only one at a time will show in the Light Lister. To see the list of instances, click the down arrow button, located next to the clone's name. This expands the list of instances. |
| 5. | Set Light_Key's Multiplier to 0.95. Select the same light's color swatch to open the Color Selector; then set the color to a very pale red. RGB values of (255, 222, 219) work well.Tip | One of the best features of the Light Lister is that the light being adjusted does not need to be selected. |
| 6. | Select the Light_Fill's Multiplier and set it to 0.5we'll keep it brighter than fill lights usually are because of the number of faces that are obstructing the light. Open the Color Selector, and give the light a pale gray-green color, somewhat like (216, 225, 214). This will give the impression of color bleed from the surrounding foliage. | 7. | Clone the Rendered Frame Window, then render the Cam Close viewport and compare the two images (Figure 13.29).Figure 13.29. The scene is a bit darker now, especially behind the giant's head and on the side of his face.
 |
The initial lighting is almost finished. Let's add a light to represent the glowing crystal and its effect on the character's torso and the surrounding organic matter.
1. | In the Top viewport, create an omni light. Its specific location is not important. | 2. | With the light still selected, click the Align tool in the Main toolbar. Before the Align Selection dialog opens, you need to select the object to which the light will be aligned. Press the H key to open the Pick Object dialog, then select Sphere01 from the list. | 3. | In the Align Selection dialog, check the X, Y, and Z Position check boxes and select Pivot Point in both the Current Object and Target Object areas. This will place the omni light at the center of the crystal (Figure 13.30). Click OK to execute, and close the dialog.Figure 13.30. Use the Align tool to position the omni light at the center of the crystal.
 | 4. | Rename the light Light_Crystal. In the Modify panel, turn Shadows on. Also, make sure mental ray Shadow Map is selected. Set the Multiplier to 1, and change the light's color to a light blue, similar to (162, 165, 225). | 5. | Select Sphere01, right-click in the viewport, and choose Properties from the Quad menu. In the Rendering Control area, uncheck Cast Shadows. This will prevent the crystal from obstructing the light that is cast from the omni. The crystal is also a light source in the scene and should not cast shadows from other lights. | 6. | Render the scene.The omni light's shadows are definitely not what we need in the scene (Figure 13.31). Omni lights spread rays in all directions and often cast improper shadows onto complicated surfaces.Figure 13.31. The omni light's shadows are not at the level of quality that we're looking for.
 | 7. | Select the omni light, and change it into a target spotlight. Correct the orientation by moving the target behind the giant. His head should be centered in the beam of light. | 8. | Turn on Use for Far Attenuation, and set Start to 30 and End to 72. This will cause the light's intensity to fall off quickly from his head to the middle of his chest. In the Spotlight Parameters rollout, make sure that the hotspot is wider than the giant's spread arms; then turn on Overshoot so that the light will illuminate the area around the character. | 9. | In the mental ray Shadow Map rollout, increase the Map Size value to 1024 pixels, then render the scene again. Figures 13.32 and 13.33 show the scene from both of the cameras.Figure 13.32. Replacing the omni light with a target spotlight allows better control over the light's shadows.
 Figure 13.33. The same scene as seen from the camera_shot1 viewport.
 |
That's a lot better. Replacing the omni light with a target spot gives us better control over the shadows that it casts, while Overshoot lets it illuminate the surrounding area. The larger Map Size value allows for finer detail in the shadows. Note, however, that your game engine and the general performance desired for the game may limit just how large any bitmap, including a shadow map, can be.In the next section, we'll look at painting color and light onto specific vertices.VertexPaint 3ds max has a rich toolset for modeling, animating, and lighting in a variety of work styles and environments. One of the tools aimed squarely at the game industry is the VertexPaint modifier. In essence, this tool bakes lighting values directly into a model's geometry by means of an easy-to-use painting interface. Each vertex processed by the game engine holds data about its coordinates, color, lighting, and material. Each vertex's lighting value is determined, then blended with the lighting values of the vertices located at the opposite end of the edges that connect them. Vertex lighting is applied to each triangle that the vertex is a part of. Subdividing your scene will give you more control over the effects of VertexPaint.
1. | Continue with your current scene, or open the file Giant_VertexPaint.max from the DVD. | 2. | Make the Cam Close viewport active. Use the Dolly Camera tool in the viewport controls to move the camera back far enough to see the giant's torso. Use the Truck Camera tool to pan the image until it looks similar to Figure 13.34.Figure 13.34. Dolly the camera backward and pan to see more of the character.
Note | The VertexPaint modifier in 3ds max 7 is not completely compatible with the same modifier from previous versions. If a scene containing the VertexPaint modifier from a previous version of max is opened in max 7, the older version of the modifier will be loaded into the scene. |
| 3. | Maximize the Cam Close viewport so that it will be easier to work in. Then turn off Edged Faces mode. | 4. | Select the cage2 object; this is the green foliage that is binding the right side of the giant's body. We want to attach the two cage objects to create a single object to paint, but they are currently instances of each other. In the toolbar under the modifier stack, click the Make Unique button to change the instances into independent objects. | 5. | In the Modify panel's Edit Geometry rollout, click the Attach List button next to the Attach button. In the Attach List dialog, choose cage1 from the list, then click the Attach button. Rename the object "cage". | 6. | Expand the Modifier List and apply a VertexPaint modifier to the cage object. This will open the VertexPaint Paintbox, where you will find tools for all of your vertex painting needs.We want to start by darkening the portions of the cage above the character's left and right shoulders that aren't receiving enough light. We'll start by adjusting the brush size and the paint color. | 7. | At the top of the Paintbox, click the Vertex Color DisplayUnshaded button. Click the color swatch and choose a dark gray color; then set the Size value to 2. | 8. | Click and drag the cursor over the surfaces above the giant's left shoulder. The brush will appear as a circle with a vector pointing away from the surface. 3ds max will always keep the brush's face perpendicular to the surface normals of each triangle. Repeat the process on the areas above the right shoulder (Figure 13.35).Figure 13.35. Use the VertexPaint brush to add darkness to the vertices above the giant's shoulders. [View full size image] | 9. | Select the giant, add a VertexPaint modifier, and add shadows where you feel they are best suited. |
Tip | The VertexPaint modifier has adjustments for precise control over the brush, including using pressure data from a pen stylus to dictate variances of the brush's width. The controls can be found in the Painter Options dialog, which opens when you click the Brush Options button. | From this exercise, you can see how useful VertexPaint can be when you need to make fine adjustments to colors and lighting values without actually changing the light kit. It's a real boon for game artists who don't have the luxury of modifying the lighting scheme.Baking Materials Lighting calculations can significantly increase the time it takes to render a scene. A fairly simply modeled scene can take an inordinate amount of rendering time if global illumination, colored shadows, radiosity, and/or an elaborate lighting setup must be taken into account. In a game environment, this can result in poor-quality renderings, dropped frames, and slow or erratic play response. The solution is to apply the effects of the lights, shadows, and textures as materials to the objects, a process commonly known as baking.The following tutorial shows how to bake various lighting-related elements so that they will work efficiently in a game.
1. | Open the file entitled Giant_VertexPaint.max from the DVD. This is similar to the project that was completed at the end of the previous exercise, except that the model is broken into two pieces, giantHead and giantBody. | 2. | Select giantHead, then open the Material Editor and highlight an unused slot. Click the Get Material button in the horizontal toolbar. | 3. | In the Material/Map Browser, select Selected in the Browse From section, then double-click giant_skin to place that material into the selected material slot (Figure 13.36).Figure 13.36. Select the giant's giant_skin material in the Material/Map Browser.
Look at the material and you will notice that it is an uncomplicated material with a Falloff map in the Diffuse Color slot. | 4. | With giantHead still selected, add a UVW Map modifier and set the Mapping type to Shrink Wrap. Use the Edit UVWs dialog to stitch the appropriate edges together. (Check the texturing chapters in this book for more on UV mapping.) | 5. | Click Rendering > Render To Texture from the 3ds max menu bar. This opens the Render To Texture dialog (Figure 13.37). This dialog will determine the object to be baked, the output location for the new maps generated, what objects to consider in the rendering, and the type of map to be baked.Figure 13.37. The Render To Texture dialog.
 | 6. | In the Output section of the General Settings rollout, click the "…" button; then assign the folder in which the new map will be placed. | 7. | In the Objects to Bake rollout, check the Enabled check box in the Selected Object Settings section; then choose All Selected at the bottom of the rollout. These settings will cause max to consider the lighting effect of all the objects in the scene when generating the map for the giant's new material. | 8. | In the Output rollout, click the Add button to open the Add Texture Elements dialog. This dialog, similar to the Render Elements feature discussed earlier, will allow you to choose which features of the rendering will be added to the new map. Select CompleteMap from the Available Elements list (Figure 13.38). In the Target Map slot, select Diffuse Color from the drop-down list.Figure 13.38. Select CompleteMap in the Add Texture Elements dialog.
 | 9. | In the Selected Element Common Settings section of the Output rollout, select Diffuse Color from the Target Map Slot drop-down list and set the Map Size to 1024. This will allow more definition to be spread across the surface of the model. | 10. | Click the Render button at the bottom of the dialog. 3ds max will show several progression bars as the texture is being rendered. Once completed, a new Shell material is created and applied to the giant. The newly rendered map, including shadows, will appear in the viewport, while the original material shows during true renderings. | 11. | An Automatic Flatten UVs modifier is now at the top of the stack. In the Display section, choose Show No Seams to hide any bright green seam indicators that will obstruct your view. Your Cam Close viewport should look like Figure 13.39.Figure 13.39. The Cam Close viewport before (left) and after (right) the Render To Texture is executed. [View full size image] |
Try moving the target for the Light_Special spotlight. As you can see in the viewport, the shadows are baked into the material applied to giantHead. Open the Material Editor and get the material that is currently applied to the object; you will see that it is now a Shell material with the baked material showing in the viewports and the original material showing in the renderings. This Shell material is much more game-friendly than the scene's original lights and materials setup. |