Lab 4: UV Texture Mapping with Blender

Introduction

The lab today will focus on the texturing process of the game development pipeline. Specifically, we will look at how to take an image texture and apply it to our model within OGRE.

While there are many ways to map an image onto a model, we will be looking at the most flexible technique used in virtually all games. This technique is known as UV mapping. UV mapping allows the texture artist to manually specify which vertices map to which texels within an image. Then during the texture/fragment shading phase of the graphics pipeline , the color values of the areas between the vertices may be determined through a clever interpolation of the UV values at each vertex.

To generate the UV coordinates we will be using Blender. Blender will allow us to take our model and automatically map it into our image space, otherwise known as "unwrapping". Unwrapping is a process which basically amounts to cutting our mesh into pieces which may then be projected down into 2D space; similar to cutting up a square cardboard box and laying it out flat on the ground. This, by itself, can be a time consuming process if done by hand. Fortunately, all modern 3D graphics programs feature some sort of automatic unwrapping algorithm which determines an ideal way to cut and project the mesh. The unwrapping algorithm, in the case of Blender, is known as LCSM (least-squares conformal maps). LCSM is basically a least-squares optimization that tries to minimize distortion of the generated projection. The reasearch paper which introduces LCSM may be found here, for those that are interested.

The unwrapping algorithm will do an ok job of unwrapping your mesh, but to get optimal results you will need to help it out by marking seams which the algorithm should cut along. These seams will allow for a better, more intuitive projection.

The best way to verify that your unwrap is good is to use a test texture which will visually indicate where distortion is occuring. The test texture is simply a repeating pattern, which after being mapped to the mesh, will stretch in poorly unwrapped areas. While there most likely be some degree of stretch when dealing with any moderately complex mesh, you can help minimize the problem by picking good seams.

Once you are done unwrapping, you will generate a UV template which can then be exported out and used by the texture artist to help create the texture. After the texture is created, and added as input to the material, it should be mapped correctly to the mesh.

Lab Requirements

You will be working either individually or in teams of two. You will need to do the following:

UV Unwrapping and Template Generation

Countless quality tutorials exist on UV unwrapping within Blender so I will omit one here. However, I will provide you a demonstration within lab to jumpstart the process. For addition reference consult the manual as well as these tutorials: unwrapping (NOTE: in newer versions of Blender, "LSCM unwrap" is labeled "unwrap", unwrapping, and texture-generation with Gimp . I would recommend doing the first tutorial, as it is rather quick, and skim through the second.

Once you have your mapped your UVs you will need to save out a UV template image. The template will serve to inform the texture artist where he will need to draw to have it properly map to the model. The last section entitled, "Saving your UV Layout," of the manual explains how to save a UV layout to an image file.

Generating a Texture

You can generate a texture using Gimp: a free, cross-platform, 2D image editing program similar to Adobe Photoshop. To generate a texture you will need to load up the template file from before in Gimp.

Ideally, you should create a layer containing only this template with some degree of layer transparency. Below this layer you should have the texture layers that you will be working with. Once you have completed your texture, you should turn off visibility of the template layer and export out. I would suggest exporting your final texture as a PNG or TGA as they tend to provide high quality output.

The second tutorial link above gives good tips on how to effectively generate texture maps with Gimp. As always, consult the manual or ask questions for more detail on any of the steps.

Bringing the Model Into Ogre

Once your texture is generated you will need to set it as input to one of your Blender materials. The manual covers how to do this. Once this is done and your model renders with the texture properly, go ahead and run the OGRE Mesh Exporter like we've done before. After you export, the generated material file should reference the texture image properly. Now all we need to do is copy the material, mesh, and texture images to the Ogre media folder and create our OGRE entity like we normally would. If everything went well you should now have a textured entity within your world.