Rendering to a Texture


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 image from book 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 25.2, resembles the Render Scene dialog box, including a Render button at the bottom edge of the interface.

image from book
Figure 25.2: The General Settings rollout of the Render to Textures panel includes settings for all objects

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.

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.

General Settings

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.

Selecting objects to bake

In the Objects to Bake rollout, shown in Figure 25.3, a list displays exactly which objects, subobjects, and channels will be included in the rendered texture. The Edge Padding defines the overlap in pixels of the texture.

image from book
Figure 25.3: The Objects to Bake rollout of the Render to Textures panel lets you specify which objects are baked into the texture map

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 Normal Map 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.

Output settings

The Output rollout, shown in Figure 25.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.

image from book
Figure 25.4: The Output rollout of the Render to Textures panel lets you choose which texture elements are baked

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.

Tip 

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 recreates effects created by limited light bounces resulting from surrounding objects. This option is new to 3ds Max 9.

Baked Material and Automatic Mapping settings

The Baked Material and Automatic Mapping rollouts, shown in Figure 25.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.

image from book
Figure 25.5: The final two rollouts of the Render to Textures panel include settings for handling the baked material and how the texture is mapped

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.

Tutorial: Baking the textures for a dog model

To practice baking textures, we bake a complete map of just the dog's head. Now I need to find a game engine to run it in.

To bake a dog's head texture, follow these steps:

  1. Open the image from book Doberman.max file from the Chap 25 directory on the DVD. This file includes a dog model created by Viewpoint Datalabs.

  2. Select Rendering image from book Render to Texture (or press the 0 key) to open the Render to Textures dialog box.

  3. Select the dog's body object. In the Render to Textures dialog box, set the Threshold Angle to 75 in the Automatic Mapping rollout, and make sure that the Rendered Frame Window option in the General Settings rollout is set. In the Output rollout, click the Add button and double-click the CompleteMap option. Set the Map Size to 512, select the Diffuse Color option as the Target Map Slot, and click the Render button.

Figure 25.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.

image from book
Figure 25.6: A texture map created with the Render to Textures panel




3ds Max 9 Bible
3ds Max 9 Bible
ISBN: 0470100893
EAN: 2147483647
Year: 2007
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net