3D games pose an interesting dilemma—creating interactive scenes that are displayed in real time with the highest quality graphics. To achieve this, game developers use a number of tricks designed to speed up the rendering time. One of these tricks is pre-rendering textures that include all the lighting information and applying these pre-rendered textures as texture maps. This allows advanced lighting solutions such as global illumination to be included within a game without requiring extra time to render such a complex solution. The process of applying prerendered textures as maps is called baking a texture.
Rendering textures is a significant part of the rendering process, and baking a texture doesn't remove this step; it simply completes the step beforehand, so that the game engine doesn't need to do the texture calculations.
Another common efficiency trick is to use normal maps. Normal maps calculate the lighting results used to light small details that stick out from the surface of an object. These details are then re-created using a normal map that is applied back onto a simplified version of the object. The normal map allows these details to be simulated without the extra polygons used to create them. By allowing simple base objects to have details such as bolts and rivets without the extra polygons, the objects can be redrawn quickly without losing their visual quality.
This chapter covers some of the features found in Max that enable the amazing graphics that are found in the latest real-time games.
When 3D models are used in games, the color and material data for the models is stored in channels. The game engine then knows that if it wants to change the color of a group of vertices because of an explosion that has happened, it just looks in the preset channel, finds the vertices it needs, changes the color, and then goes on with the game.
Working with channels is a very efficient way to interface with the gaming engine, but a sloppy game developer can introduce a model to the game engine with all sorts of unneeded or exaggerated channels. If this happens, the game engine can ignore the extra channels and get the wrong information, which can cause your hero to march off into battle without a weapon. Worse, it can crash the system.
To prevent problems and to streamline the number of channels that are included with game models, Max includes a Map Channel Info editor that you can use to manipulate the various channel data. This editor, shown in Figure 34.1, can be opened using the Tools Channel Info menu command.
The Map Channel Info dialog box shows lots of information, including the Object Name; its ID; its Channel Name; the number of Vertices, Faces, and Dead Vertices (unattached vertices); and its Size. With this information, you can quickly determine which channels are taking up the most space and eliminate them.
All objects include some default channels for mesh, which holds the geometry; vsel, which holds the selected vertices; −2:Alpha, which holds the alpha channel information; −1:Illum, which holds illumination values; and channel 0:vc, which holds vertex color information. Objects also include at least one default map channel (even if it is empty). These channels cannot be deleted.
Cross-Reference
Vertex colors are covered along with painting on objects in Chapter 18, “Creating Compound Materials and Using Material Modifiers.”
The interface lets you Copy and Paste selected channels. You can give each channel a name with the Name button. Beneath the Copy button, text appears that lists the information currently copied in the Copy Buffer. Selected channels can be copied only between channels that have the same number of vertices.
The Clear button clears out the selected channels, but you cannot clear a map channel if there is another map channel above it. The Add button adds a new map channel to the object. Objects can hold as many as 99 map channels. The Clear and Add buttons also apply UVW Mapping Clear or UVW Mapping Add modifiers to the Modifier Stack. The Paste command also adds a modifier. These modifiers are convenient because they can easily be removed or reordered in the Stack. If changes have been made in the Modifier Stack, the Update button reflects these changes in the Map Channel Info dialog box.
The SubComp button shows the channel components if they exist. For example, map channels can be broken into X, Y, and Z components, and other channels such as Alpha have R, G, and B components. The Lock button holds the current channels even if another object is selected.
After new channels have been created, you can recall them at any time using the Select by Channel modifier. This modifier is found in the Modifiers Selection Select by Channel menu command. Using this modifier, you can choose to Replace, Add, or Subtract a given channel from the selection. The available channels for the selection are listed by their channel name in a drop-down list.
When working with a game engine, game designers are always looking for ways to increase the speed and detail of objects in the game. One common way to speed game calculations is to pre-render the textures used in a game and then to save these textures as texture maps. The texture map takes more memory to save but can greatly speed the rendering time required by the game engine. This process of pre-rendering a texture is called texture baking.
Caution
If you bake a texture into an object and then render it with the rest of the scene, the object gets a double dose of light.
Texture baking can be accomplished in Max using the Rendering Render to Texture menu command (or by pressing the 0 key). This opens the Render to Texture dialog box. In several ways, the Render to Texture dialog box, shown in Figure 34.2, resembles the Render Scene dialog box, including a Render button at the bottom edge of the interface.
To create a baked texture, select a Texture Element from the Output rollout and click the Render button. Clicking the Render button creates the baked texture for the selected object and saves it in the directory specified in the General Settings rollout. It also applies an Automatic Flatten UVs modifier to the Modifier Stack and applies a Shell material to the object. The Shell material contains the object's original material along with the new baked material. You can select which material is displayed in the viewport and which is rendered using the options to the bottom right of the Render to Texture dialog box.
Note
You also can select Use an Existing Channel for mapping coordinates. This is a good choice because the Auto Unwrap option doesn't have the control over the UV coordinates that you may want, and sometimes it does a poor job of unwrapping the mesh.
The interface also includes an Unwrap Only button. This button can be used to flatten the UVW Coordinates for the selected objects and to automatically create a map channel.
The General Settings rollout includes an output path where the baked texture is saved. The file is saved by default using the Targa file format. The Skip Existing Files option renders only those elements that don't already exist in the designated directory. The Rendered Frame Window option displays the resulting map in the Rendered Frame Window along with saving the image as a file. For the render pass, you can select which rendering settings to use, including the mental ray rendering engine. The Setup button opens the Render Scene panel, where you can change the render settings.
In the Objects to Bake rollout, shown in Figure 34.3, a list displays exactly which objects, subobjects, and channels will be included in the rendered texture. The Padding value defines the overlap in pixels of the texture. The Objects to Bake rollout also includes a Presets list that lets you save and reload defined settings.
The Projection Mapping section lets you enable the creation of a normal map using a Projection modifier. These settings are covered in detail in the “Creating Normal Maps” section that appears later in this chapter.
The Mapping Coordinates section lets you choose to use the mapping coordinates of the Object or the Subobject selection contained within a specified channel, or you can select to use the Use Automatic Unwrap feature, which automatically flattens the mapping coordinates. If the Use Automatic Unwrap option is selected, you can set the mapping options in the Automatic Mapping rollout. By default, unwrap mapping uses channel 3, but you can change this channel if you wish. If a different mapping uses channel 3 and you don't change this, the new mapping replaces the old one. The Clear Unwrappers button removes any existing Unwrap UVW modifiers from the object's stack.
You can select to bake an Individual object, All Selected objects, or All Prepared objects, which are all objects with at least one texture element.
The Output rollout, shown in Figure 34.4, lists the texture elements that are included in the texture map. The Enable option can be used to disable the selected texture element, or elements can be deleted with the Delete button.
Clicking the Add button lets you select the type of texture elements that you can render. You'll want to use different maps depending on the purpose of the map, and you may want to render several at a time. The available types are CompleteMap, SpecularMap, DiffuseMap, ShadowsMap, LightingMap, NormalsMap, BlendMap, AlphaMap, and HeightMap. You can also change the map size or use the Automatic Map Size option, which bases the map size on the object size. Some map elements present a list of components to include in the map. These components appear below the size settings.
If the mental ray renderer is selected, then Ambient Occlusion is added to the list of available texture elements. The Ambient Occlusion option creates a map that re-creates effects created by limited light bounces resulting from surrounding objects.
The Baked Material and Automatic Mapping rollouts, shown in Figure 34.5, provide a way to keep the existing object material using the Shell material. The Clear Shell Materials button removes the Shell materials for the baked objects and restores their original materials.
In the Automatic Mapping rollout, you can set how the mapping is applied. If the Use Automatic Unwrap option in the Objects to Bake rollout is enabled, then the object to be baked has the Automatic Flatten UVs modifier applied. For this type, you can set the Threshold Angle (which is the difference between the normals of adjacent faces; if the angular value is greater than the Threshold Angle value, then a hard edge is created between the faces), the Spacing (which is the amount of space between different map pieces), and whether map pieces can be rotated and used to fill in holes of larger map pieces.
The size of the texture map depends on the size of the object, but you can set a Scale value for greater resolution and set Min and Max values to keep the maps within reason. By default, maps are saved to the /images directory, but you can select a different directory if you prefer. The Nearest Power of 2 option causes the map to be optimized for use in memory to a square pixel size that is a power of 2, such as 8×8, 16×16, 32×32, or 64×64.
Note
Most game engines require square texture maps because they are efficiently loaded into memory. Main characters can use texture maps that are 1024×1024 or even 2048×2048, but background characters and props usually only have textures maps that are 256×256 or 512×512, so clustering is important to get as much into the textures as you can.
To practice baking textures, you'll bake a complete map of just the dog's head.
To bake a dog's head texture, follow these steps:
This file includes a dog model created by Viewpoint Datalabs.
Figure 34.6 shows the resulting texture map. If you look in the Modify panel, you'll see that the Automatic Flatten UVs modifier has been applied to the object. If you look at the material applied to the object, you'll see that it consists of a Shell material.
Normal maps are becoming more common in games because they offer a way to increase the bump details of a model by mapping high-detail bump information onto a low-resolution model. Normal maps are created using the Render to Texture interface and applied to an object using the Normal Bump map type found in the Material Editor.
The Normal Bump map type is typically applied as a bump map in the Maps rollout and includes a separate button, shown in Figure 34.7, to apply an additional bump map.
Caution
Normal maps can be displayed in the viewports only if the DirectX display driver is selected.
The Projection modifier is used to create a normal map. It works by being applied to a low-resolution object, and then you pick a high-resolution object that is similar to the low-resolution one. The Projection modifier surrounds the object with a cage that can be manipulated to include all the object details. The Projection modifier is applied using the Modifiers UV Coordinates Projection command.
Within the Modifier Stack, the Projection modifier includes three subobject modes: Cage, Face, and Element. The Geometry Selection rollout includes a list of objects, a Pick button, and a Pick List for selecting the high-resolution object to be used.
The Cage rollout includes settings for displaying and pushing the cage out from the surface of the object. A Tolerance setting is used for wrapping the cage about the surface. The Selection Check rollout informs you if the Material IDs or Geometry faces are overlapping.
With a Projection modifier applied to a selected object, the Projection Mapping option can be enabled in the Objects to Bake rollout of the Render to Texture dialog box. The object can actually include several Projection modifiers, so a drop-down list lets you select the one to use, or you can use the Pick button to select a target object in the viewports.
The Options button in the Render to Texture dialog box opens the Projection Options dialog box, shown in Figure 34.8. Using this dialog box, you can set the projection method, determine how to resolve how vertices get projected, and define the Map Space.
At the top of the Projection Options dialog box is the Source object. The Synch All button causes each object to use its active source for the projection. The two projection methods are Raytrace, which traces each normal line from its source to its target, and UV Match, which works by matching the UV coordinates between the source and the target objects.
For transparent objects, two projection rays may hit the same point. The Resolve Hit options let you set which one is selected, either the Closest or the Furthest. Most projections use the Tangent Map Space, but you can select to use the World, Screen, or Local Map Spaces also.
Note
Before the Projection modifier is applied, you need to have the high-res object and the low-res object positioned at the same place.
For this example, we reuse the optimized gator created earlier when mesh modifiers were covered. The ProOptimizer modifier was used to reduce this high-res gator model from 34,000 faces to fewer than 1,000. This kind of reduction represents a huge step down for the quality of the model, but it enables it to be lightning fast when used in a game. The normal map makes it possible to use the lower poly model while recovering much of the display quality.
To create a normal map for the optimized gator model, follow these steps:
Figure 34.9 shows the resulting normal map rendered on the right gator.
If you're working with games, then you'll want to use these features to help keep your models small and fleet. This chapter covers the following topics:
The next part takes up the topic of animation again, starting with animation modifiers.
3.147.58.194