Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

3D Game Programming All In One (2004)

.pdf
Скачиваний:
139
Добавлен:
17.08.2013
Размер:
17.91 Mб
Скачать

278 Chapter 8 Introduction to Textures

Figure 8.7 Vehicle detail and structure.

Figure 8.8 Player clothing, skin, and other details.

Figure 8.9 Distant objects.

still make out the sense of a solid glasslike surface.

Of course, technological features are not the only things that can be enhanced through textures. In Figure 8.8 the brawler about to enter the tavern is attired in the latest stylish leather brawling jacket. He is obviously somewhere around 40 years of age, judging by his classic male-pat- tern baldness, and the bat is a Tubettiville slugger. Okay, okay, the bat is a stretch, but if it were turned over 180 degrees, you would be able to see the Tubettiville logo, and then you could tell! Also note the use of the texture specifying the tavern name, named in honor of a famous Delta Force 2 player, Insomniac.

Look at the moon in Figure 8.9. Look again, closer. Does it look familiar? It should, because the moon texture in that picture is an actual photograph of the full moon, taken outside my house with a digital camera and then used to generate the moon texture. The rest of the scene is generated using the Torque Engine with appropriate nighttime lighting parameters set.

I think by now you have a pretty good idea why I say that textures are the unsung heroes of 3D gaming. They really make a huge difference by conveying not only the obvious visual information, but also the subtle clues and feelings that can turn a good game into a great experience.

Team LRN

Paint Shop Pro

279

Paint Shop Pro

You are going to be creating your own textures as you travel through this book, and to do that you'll need a good tool for texture and image manipulation. Well, the good folks at JASC Software have graciously allowed us to include their great image processing tool, Paint Shop Pro, on the companion CD for you to use.

I've been using Paint Shop Pro for about 10 years, I think. In the early days, I only used it for converting file types, because that was about all it could do. Nowadays, though, it is a fully featured image processing and image generation tool, with scanner support, special effects and filters, image analysis statistics, and the whole nine yards.

First, you'll need to install Paint Shop Pro, if you haven't already run the Full Install from the CD.

Installing Paint Shop Pro

If you want to install only Paint Shop Pro, do the following:

1.Browse to your CD in the \PSP folder.

2.Locate the Setup.exe file and double-click it to run it.

3.Click the Next button for the Welcome screen.

4.Follow the various screens, and take the default options for each one, unless you know you have a specific reason to do otherwise.

Getting Started

To get this party rolling, we're going to just blast through and create a couple of textures that you can use later for whatever grabs your fancy. We'll cover just the tools and steps we need to get the job done. In a later section we'll cover the most common tools in more detail.

Creating a Texture

So, let's get down to brass tacks and create a texture from scratch. We'll create a wood texture using the built-in capabilities of Paint Shop Pro.

1.Launch Paint Shop Pro and select File, New.

2.A New Image dialog box opens up. Set the width and height dimensions to 128 pixels (see Figure 8.10) and click OK.

3.We now have a blank image to work with. Choose the menu item Effects, Texture Effects, Texture, and the Texture dialog box will appear, as in Figure 8.11.

4.In the visual list at the lower part of the Texture dialog box, select Woodgrain. You'll have to scroll down through the list to the bottom.

Team LRN

280 Chapter 8 Introduction to Textures

5.Click on the color box at center-right. You will get a Color dialog box, as shown in Figure 8.12.

t i p

Most of the image processing tools in Paint Shop

Pro have an Auto Proof button that looks like this:

If you are using something newer than an old Pentium 100 computer, you should probably have this button pressed. It allows you to see the changes in your image as soon as you make them, rather than waiting until you click the OK button to close whichever dialog box you are using.

6.Change the value in the R (for red) box to 139, in the G (for green) box to 87, and in the B (for blue) box to 15. The H (hue), S (saturation), and L (light) boxes will automatically change to match.

Figure 8.10 Creating a new blank 7. Click OK to close the Color dialog box.

image.

8. Change the other settings in the Texture dialog box to match those in Table 8.1.

 

Table 8.1

Texture Dialog Box

 

Settings

 

 

 

Attribute

Value

 

Size

100

 

 

Smoothness

15

 

 

Depth

9

 

 

Ambience

0

 

 

Shininess

4

 

 

Angle

336

 

 

Intensity

50

 

 

Elevation

37

 

 

 

 

 

Figure 8.11 Texture dialog box with woodgrain texture.

9.Click OK to close the Texture dialog box.

10.Now you should have a bona fide woodgrain texture, like the one shown in Figure 8.13, that you can use for things like walls, planks, ladders, the wooden stock on a weapon, barrels, and whatever else you can come up with.

Team LRN

Paint Shop Pro

281

11.With this texture, you can experiment with different image processing effects and touchup tools in Paint Shop Pro. Go ahead and give it a try.

Okay, that was so much fun, let's do another. This time we are going to tweak an image a bit searching for a specific look. The next texture will be a sort of roughwall look that you might find on a painted cement block, or maybe a freshly poured sidewalk, or something like that. We'll call it the sidewalk texture, for convenience.

1.If it isn't still open, launch Paint Shop Pro.

2.Select File, New.

3.Set the width and height dimensions to 128 pixels and click OK. (Take another look at Figure 8.10 if you

need to refresh your memory.)

Figure 8.12 Color dialog box for woodgrain.

4.Select the menu item Effects, Texture

Effects, Texture, and the Texture dialog box will appear again, just like before, as depicted in Figure 8.11.

5.This time we'll do something a bit different from the previous image. Locate the Texture frame at center-left. Click on it to open a visual menu of textures, and choose Concrete.

You should get a texture like the one shown in the boxes in the dialog box in Figure 8.14.

6.Click on the color box at center-right to get the Color dialog box again.

Figure 8.13

Woodgrain texture.

7.Using Figure 8.15 as a guide, change the value in the R box to 218, in the G box to 181, and in the B box to 110.

8.Click OK to close the Color dialog box.

9.Change the other settings in the Texture dialog box to match those in Table 8.1.

10.Click OK to close the Texture dialog box. You should get a new texture like the one shown in Figure 8.16.

Now this texture is quite a bit darker than I want it to be. I'm looking for a gray with a hint of beige or tan color, so what we'll have to do is touch it up a bit. First, we want to brighten the highlights and, at the same time, darken the shadows a bit.

Team LRN

282 Chapter 8 Introduction to Textures

Figure 8.14 Texture dialog box with default preset.

Figure 8.15 Color dialog box for sidewalk texture.

To do this, we'll use the Highlight/ Midtone/Shadow tool.

11.Select Adjust, Brightness and Contrast, Highlight/Midtone/Shadow. You'll get the Highlight/Midtone/Shadow dialog box shown in Figure 8.17. Change your settings to match those in the figure.

As you can see with Figure 8.18, the texture details now stand out in relief quite a bit more. This is goodness. However, the color is way too rich, or vibrant, for use as a sidewalk or wall texture, in my humble opinion.

What we want to do now is tone down the richness of the color. We can do that by using the Hue/Saturation/Lightness tool. Now, we could have done this part using the Color tool when we created the color. And I tried! But it wasn't close enough, so using the Hue/Saturation/ Lightness tool allows us to tweak the color in the direction we want.

12.Choose Adjust, Hue and Saturation, Hue/Saturation/Lightness to get the Hue/Saturation/Lightness dialog box, as shown in Figure 8.19.

13.Set the Hue to 0, the Saturation to 70, and the Lightness to 0, and then click OK.

This will take the edge off the richness of the color quite a bit. If you look at Figure 8.20 and compare it with Figure 8.18, you can see the difference. You can use the Undo/Redo feature of Paint Shop Pro to compare your own versions of these images. Select the Edit, Undo and the Edit, Redo menu items to switch back and forth between the before and after versions of your own creation.

Team LRN

Paint Shop Pro

283

Now that the color is where we want it, let's roughen it up a bit. The texture is a bit too smooth, sort of like taffy. A sidewalk usually looks grainier. To do this, we'll add noise.

14.Choose Adjust, Add/Remove Noise, Add Noise. You'll get the Add Noise dialog box, as shown in Figure 8.21.

15.Set the Noise value to 19 percent.

16.Select the Gaussian button.

17.Check the Monochrome box. Compare Figure 8.22 with Figure 8.20, and you'll see the differ- ence—the newly added roughness to the surface.

You should now have two images open in your Paint Shop Pro window: the first one being the woodgrain texture, and the other being the sidewalk texture. In the next section you'll learn how to save those images for later use.

Working with Files

Figure 8.16 Initial sidewalk texture.

We want to get those images saved without any further ado, but first I want to show you something. You're going to

launch the fps demo game that comes Figure 8.17 Highlight/Midtone/Shadow dialog box. with the Torque Engine.

Launching the fps Demo Game

1.Leave Paint Shop Pro running and task switch (Alt+Tab) to the Windows desktop.

2.Using the Windows Explorer, browse into the C:\3DGPAi1 folder and then double-click on the fps demo shortcut.

3.When the GarageGames/Torque splash screen appears, click on the Start Mission button.

4.When the Mission dialog box appears, clear the Multiplayer check box.

5.Click on Scorched Planet to highlight that line.

6.Click on Launch Mission.

Figure 8.18

Enhanced highlight sidewalk texture.

Team LRN

284 Chapter 8 Introduction to Textures

When the game finishes loading you should get a view pretty well identical to the one in Figure 8.23, except it will be in color, of course. The floor will be bright orange, and the beams above you will be magenta. This odd coloring is deliberate—you are going to save your own textures in place of these two textures; this will make it easy for you to see if your changes have taken effect.

7. Resist the natural impulse to run around and blow things up. Instead, press the Escape key to exit the game (well, try to resist the natural impulse to run around and blow things up, anyway).

8. Click Quit.

Saving Texture Files

Okay, now that you have the "before" view recorded in your mind, we'll finally get to saving

Figure 8.19 Hue/Saturation/Lightness those images. Switch back to Paint Shop Pro now, dialog box.

and follow this procedure to save your files:

Figure 8.20

Desaturated sidewalk texture.

1.Click on the woodgrain image to bring it to the front (making it active).

2.Select File, Save As, and the Save As dialog box will appear.

3.In the Save As dialog box, make the type be JPG by scrolling through the Save As Type list and selecting JPG – JIFF Compliant.

4.Browse your way to C:\3DGPAi1\fps\data\interiors\evil1.

5.Name your file wood.jpg—the name must be exact.

6.Click OK.

7.You will get a dialog box that says "C:\3DGPAi1\fps\data\interiors\evil1\wood.jpg already exists. Do you want to replace it?" Click Yes.

Repeat steps 1 to 7 for the sidewalk image, using the name drk_cem.jpg.

Now, task switch back to the desktop and run the fps demo game again, just as you did before. When you spawn in the game you will now see the floor rendered with your new texture and the overhead beams rendered with the woodgrain texture you created. If either the floor or the beams look like they did in your "before" view, then you've

Team LRN

Paint Shop Pro

285

probably made an error in the file name or perhaps saved them in the wrong folder. Double-check your work, and everything should turn out fine.

Congratulations! Now you are an artist.

t i p

The actual textures used for this platform object are saved in the evil1 folder as Original wood.jpg for the overhead beams and Original drk_cem.jpg for the floor. You can use the originals to replace your own textures if you want to see what they looked like.

PNG versus JPG

Paint Shop Pro supports many, many file types. If

Figure 8.21

you select File, Save As, you'll get the Save As dialog

box. If you click on the Save As Type combo box, you'll get a whopping great hockey sock full of available file types. There are two of particular interest to us: JPEG (Joint Photographic Experts Group) and PNG (Portable Network Graphics). In Windows, the JPEG format file extension is "JPG"; this has more common usage than "JPEG", so that's the term I will use.

When you save files in the JPG format, the images are compressed. The type of compression used is called a lossy compression. This means that the technique used to

squeeze the image information into less space throws away some of the information. This is not necessarily a Bad Thing. The people who devised the JPG format were pretty clever and were able to specify rules that guide the software in what to keep, what to throw away, and how to modify the information. So although there is loss of information, the effect on the image is pretty negligible in most cases.

Add Noise dialog box.

Figure 8.22 Final sidewalk texture.

But there is an effect. Try this little

experiment to see for yourself: Figure 8.23 Spawn view in the fps demo game.

Team LRN

286 Chapter 8 Introduction to Textures

1.Create a new document the same way you did earlier with the two textures.

2.Make sure you have your foreground color set to black in the Materials palette (see Figure 8.24) and the background set to medium gray.

 

 

t i p

 

 

To change the foreground color, find the Materials palette at

 

 

the right side, below the toolbars. There are two sets of

 

 

overlapping color squares: a large and a small. Locate the

 

 

upper-left large color square, which is called the Foreground

 

 

and Stroke Properties box. Click this square and a Color dia-

 

 

log box will open. Select black and then close the dialog box

 

 

by clicking OK.

 

 

The rectangle on the lower right is the Background and Fill

 

 

Properties. You change it in the same way.

 

 

If you can't find the Materials palette, choose View, Palettes,

Figure 8.24 Materials palette.

Materials.

 

 

 

3.Choose Adjust, Add/Remove Noise, Add Noise to get to the Add Noise dialog box.

4.Select the Gaussian and Monochrome options.

5.On the right-hand side of the dialog box, set the Noise percentage to 60 percent.

6.Click OK, and the blank image will be filled with speckles and dots, similar to the image shown in Figure 8.25.

7.Next, select the Preset Shape Tool, the third last icon on the Tool palette.

8.Draw a shape in the middle of your image—any shape will do. Figure 8.26 will give you an idea.

9.Now select File, Save As, and the Save As dialog box will appear.

Figure 8.25

Noise

10. In the Save As dialog box, make the type be JPG by scrolling

through the Save As Type list and selecting JPG – JIFF

image.

 

 

 

Compliant.

11.Give the file a name (I'll use "testing"), and save it wherever you can remember to find it again. Make sure you use a unique name so that you don't overwrite an existing file.

12.Click OK.

13.Now select File, Save As again, but this time select PNG format. This is an open standard file format used in many parts of the computer industry.

14.Close both of your image windows.

Team LRN

Figure 8.26 Noise image with shape.

Paint Shop Pro

287

15.In the File menu, near the bottom is the Recent Files submenu, which contains a list of the names of recently used files. If you used the same file name that I did, you should see testing.png and testing.jpg in the list. Open both of them.

16.Use the Zoom tool, which is available via the top icon in

your Tool palette (see Figure 8.27). Click on the icon, then select the Zoom tool from visual menu—the toolbar icon will change to reflect the chosen tool. Next, click once in

each image to zoom it to a larger magnification. Right-click to zoom out again.

17.Compare the two images. You'll notice odd pixel artifacts around the lines of your shape in the JPG version that don't exist in the PNG version. Those artifacts are a result of the compression.

See Figure 8.28 for a zoomed view of JPG image's artifacts in the upper portion of the figure, compared to the PNG image in the lower portion. The arrows in the JPG version point to some of the compression artifacts.

On top of all that, if you repeatedly open and save JPG files, the distortion

will get worse each time you do it, as data is lost in the compression each time. You'll see it as a sort of smearing

of colors around edges, especially in

areas of high color contrast. It's simi- Figure 8.27 Tool palette, with tool names. lar to the messiness resulting from

photocopying photocopies of photocopies.

So, if JPG has these artifacts, why use it? Because with more complex images, JPG files are usually smaller than PNG files. Go ahead and try for yourself. Maybe use the one in your texture example from earlier, like the sidewalk texture. When I save the final texture as JPG, I get a file size of 6,493 bytes. As PNG, I get 19,882 bytes!

The smaller the texture files are, the more of them we can fit in a given amount of memory, and the more textures we can fit in memory, the richer the visual experience for our game.

Okay, so now you are wondering, why bother with the PNG file

Figure 8.28 Noise

type, right? Well, there is a good reason for using PNG files, of

image.

Team LRN