3D Game Programming All in One- P16

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:30

lượt xem

3D Game Programming All in One- P16

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

3D Game Programming All in One- P16: During the past several years while working on the Tubettiland “Online Campaign” software and more recently while working on the Tubettiworld game, I figure I’ve received more than a hundred queries from people of all ages about how to get started making games. There were queries from 40-year-olds and 13-year-olds and every age in between. Most e-mails were from guys I would estimate to be in their late teens or early 20s.

Chủ đề:

Nội dung Text: 3D Game Programming All in One- P16

  1. Sources 357 Then choose Image, Rotate, Free Rotate to get the Free Rotate dialog box (see Figure 11.9). Click the Right button in the Direction frame, and click the Free button in the Degrees frame. Finally, type 1.00 in the text box next to the Free button, and click OK. This will rotate the selected area 1 full degree to the right (see Figure 11.10). You should have your rotated area with the selection mar- Figure 11.8 Rectangular Selection tool icon. quee still surrounding it. Don't touch anything yet—leave the selection as it is. Now after having explained the Crop tool, I'll show you another way to crop the image that is sometimes more convenient than using the Crop tool. With the rotated area still Figure 11.9 The Free Rotate dialog box. selected, choose Image, Crop to Selection and the image will be cropped for you! You will then end up with an image as shown in Figure 11.11 suitable for use as a texture. Now compare Figure 11.11 with Figure 11.7 and you will see the difference. Original Artwork The other approach to creating textures is to use original artwork. Some people believe this is not a real option for them, because they think they can't draw or paint to save their Figure 11.10 The rotated woodgrain. lives. I tend to feel that everyone can learn the techniques required. My intent here, however, is not to teach you how to draw, so if you want to learn more, I encourage you to look into tak- ing some lessons. If you are satisfied with your artistic skills, then Figure 11.11 The cropped woodgrain image. you have another rich avenue for texture gen- eration available to you. The techniques used to convert a photograph to a texture can also be used to convert your hand-made images to textures. Another approach for creating original artwork is to create your images directly in a tool like Paint Shop Pro. You can draw freehand using the mouse or a pen tablet. Team LRN
  2. 358 Chapter 11 ■ Structural Material Textures With tools like Paint Shop Pro you have a wide variety of means for creating textures, including a specific Texture Effects tool in the Effects menu, as shown in Chapter 8. Figure 11.12 shows examples of textures created using the built-in features of Paint Shop Pro. I encourage you to explore this tool in depth. It can really be a timesaver. And you can use it to create some knockout textures. Scaling Issues When creating your textures, you will need to pay attention to the issue of scale. The sizes of the things within an image that is used to make a texture have a particular relationship to other real-world objects. We are subconsciously aware of many of these relation- ships from our exposure to the world in general and will notice when the textures are out of proportion to the items they adorn. If it's bad enough the effect can sometimes be similar to the sound of fingernails being Figure 11.12 Example textures. dragged across a chalkboard! Figure 11.13 shows two stylized houses. The bricks in house A are far too large, while the bricks in house B are more appropriately sized, yet may still be a bit too large. Yes, there are some uses for stone blocks having proportions such as those in house A, but they are rarely used in bungalow-sized or two-story Figure 11.13 Scaling bricks. homes, as depicted in the figure. The scale issue can pop up anywhere, as you can see in Figure 11.14. The texture image in the corrugated metal bridge surface is probably about 10 times larger than is appropriate. Sometimes you might need to redo the texture to match—other times you can adjust how the texture is applied to the polygons using the modeling tools. My rule of thumb is that if the texture image size is 64 pixels by 64 pixels or smaller and needs to be made larger, you should make a new texture at the larger size. Figure 11.14 Scaling error. The same goes the other way: If the image size Team LRN
  3. Tiling 359 is larger than 64 pixels by 64 pixels and needs to be made smaller, then make a new tex- ture at the smaller size. Tiling Many structures have large surfaces with repeating patterns. The best way to approach making textures for these surfaces is to create one smaller texture that is replicated many times across the surface, rather than simply making one large texture. The replication will usually take place in two dimensions. It is important to make sure that the edges of the texture align properly when they meet. Figure 11.15 shows this to good effect. You can see the obvious horizontal as well as the more subtle artifacts in house A where the tiled brick textures don't quite line up. In house B, where care was taken to ensure that the texture edges matched up correctly, those artifacts aren't visible. However, in house B in Figure 11.15 there is another obvious artifact of tiling, this time caused by asymmetric lighting effects in the texture shading. You can see each repeated texture tile—its position is marked by the presence of the darker shaded bricks in a repeated pattern. This effect can be quite subtle and difficult to detect in an image viewed in isolation. Figure 11.15 Tiled brick texture. Figure 11.16 shows the texture used in house B of Figure 11.15. Looking at it in isolation, you would be hard pressed to notice the subtly darker shaded bricks. The simplest way to fix up a texture for use as a tiled tex- ture is to copy the left edge, about 5 or 10 pixels wide, Figure 11.16 The brick texture with asymmetric shading. mirror the copy horizontally, and then paste the copy on the right side of the image. Do the same for the bottom edge. Of course, you can go from top to bottom or right to left as well. The important step is the mirroring. After placing the mirrored edges, spend a little time blending their inner edges with the interior portions of the image. Figure 11.17 shows a stone block texture that is a candi- date for use in a tiling situation. Figure 11.18 shows the texture tiled in a set of four. Again, you can see the artifacts caused by the mismatched edges. Figure 11.17 A stone texture. Team LRN
  4. 360 Chapter 11 ■ Structural Material Textures Figure 11.19 shows the left edge being copied, mirrored, and placed on the right. Figure 11.20 shows the same thing happening with the bottom edge. Finally, Figure 11.21 shows the tiled result. Figure 11.18 Poorly tiled stone Figure 11.19 Replicating the texture. left edge. Texture Types There are far too many texture types and class- es of material appear- ances for me to enu- merate them with any sort of thoroughness. Given that, there is a much smaller set of tex- ture types that are found over and over in Figure 11.20 Replicating the Figure 11.21 Properly tiled nature and man-made bottom edge. stone texture. structures. Most of the following textures are types that are used for buildings, bridges, and other man-made items in a game world. Irregular Irregular textures tend to have a general disorder and random appearance, like that shown in Figure 11.22. Dirt and grass are examples of irregular textures. Quite often irregular textures are combined with other, different irregular textures in order to give a weathered or dam- aged appearance to an area or surface. Figure 11.22 An irregular texture. Team LRN
  5. Texture Types 361 Rough Rough textures, as shown in Figure 11.23, sometimes have somewhat the same sense about them as irregular textures. They are often used as tiles on a surface like a sidewalk or rough concrete walls. Pebbled Pebbled textures are another example of textures often used for paved surfaces and stone walls. Tarmacadam pavement is an example of a finely pebbled surface when Figure 11.23 A rough texture. viewed from a distance of about 5 or 6 feet. Figure 11.24 shows a more obvious pebbled texture that could be used for a wall or deco- rative planter. Woodgrain Figure 11.25 shows a woodgrain texture that Figure 11.24 A pebbled Figure 11.25 A woodgrain has many highly variant texture. texture. bundles of lines rang- ing from fine to coarse that run roughly parallel to each other, sometimes interrupted by swirls and knots. Some kinds of stone have similar appearances. Smooth We all know when something is smooth—there are no discernable bumps or irregularities to our touch. Depicting smoothness in textures can be a little diffi- cult. We usually create a rather bland surface look and then introduce a few soft and mild irregularities in order to emphasize the smoothness. Figure 11.26 Figure 11.26 A smooth texture. shows a smooth texture. Team LRN
  6. 362 Chapter 11 ■ Structural Material Textures Patterned Patterned textures are pretty straightforward. The intent is not necessarily to convey the contour, bumpiness, or feel of a surface, but rather to represent regular shapes or patterns that appear on an item. Figure 11.27 depicts a pattern that could be used to represent the louvers of an air duct in a wall. Fabric Fabric textures emulate the appearance of things like canvas or carpet. Fabrics may be woven or not, but they all tend to exhibit fine repetitive shapes. Figure 11.28 shows a woven fabric texture that could be canvas. Figure 11.27 A patterned Metallic texture. Metallic textures tend to have a dominant color, with a strong dark shadow that follows the outer contours of the metallic object and a bright accent color that runs along raised surfaces. Figure 11.29 shows a texture that could be used for a metal tube. Reflective A reflective texture simulates the effect of a light source in the scene reflecting strongly off the surface of the tex- tured object. Figure 11.30 is such a texture that might be depicting a bright overhead light reflecting off a window. Figure 11.28 A fabric texture. Plastic Plastic textures are sim- ilar to metallic textures in their manner of shading and highlight- ing. Plastic tends to have more of an oily appearance to it at times, so the shading and highlights are often Figure 11.29 A metallic Figure 11.30 A reflective more sinuous. As texture. texture. shown in Figure 11.31, Team LRN
  7. Moving Right Along 363 the highlights tend to be less clearly defined than with metallic textures, while the light source often appears as a distinct highlight. Moving Right Along In this chapter, we examined how to collect images to use in applying textures to objects that represent real-world structures. We saw some of the processing techniques that we may need to use to prepare our images for use as tex- tures, like color matching and cropping. Figure 11.31 A plastic texture. Some of the areas that can be more problematic when considering textures for structures are scaling the images and preparing them to be "tiled" if the texture will be used in a repeating fashion. A texture that can be tiled is one whose opposite edges can be mated together without producing a noticeable seam. Finally, we explored some of the more common texture patterns and characteristics that are used in games. In the next chapter, we will look at terrains, which are often used to provide that touch of realism in our game worlds. Some of the ideas we've covered in this chapter will certain- ly be useful in the next chapter as well. Team LRN
  8. This page intentionally left blank Team LRN
  9. chapter 12 Terrains M any games take place exclusively inside buildings or structures, like tunnels. And many other games involve exclusive outdoor game play. Then there are some games that have a mix of each. When your game has an outdoor component, you need to represent the terrain, which in game terms is the combination of the topography (hilliness, for example) and ground cover (grass, gravel, sand, and so on). The topography is modeled using a 3D model, and the ground cover is represented by textures. In addition to representing the ground, you also need to represent the sky, if you want to have interesting outdoor game play. Typically, a construct called a skybox is used to repre- sent all of the sky, from horizon to horizon. Terrains Explained To understand terrains in a game development context, we need to look at the characteristics of the terrain we want to model. These characteris- tics will drive our need for the data that defines the terrain we want to make and therefore will heavi- ly influence how and where we obtain that data. Terrain Characteristics A basic unit of terrain is the tile. Essentially a ter- rain tile is a collection of polygons that form a 3D model that represents the terrain, as depict- Figure 12.1 An untextured terrain tile. ed in Figure 12.1. 365 Team LRN
  10. 366 Chapter 12 ■ Terrains When we model terrain in a game, there are a number of choices we have to make. We need to decide the level of terrain fidelity we want to achieve. Another choice is to figure out the spread of the terrain. Finally, we need to decide what sort of freedom the terrain embodies. Table 12.1 lists characteristics and the ramifications of each of these choices. Table 12.1 Terrain Characteristics Characteristic Description Fidelity Terrain fidelity measures how accurately the terrain reflects real topography found somewhere in the world—how realistic it is. The realism can be reflected in both the modeling and the textures. Modeling fidelity can be described as any of the following: Realistic: Accurate at 1:1 scale in all dimensions with high-resolution textures representing the terrain cover. Semirealistic: Accurately scaled, usually to a smaller size. Often the vertical scale is 1:1 while the horizontal scales are around 1:2. The game World War II Online by Cornered Rat Software has all of Western Europe modeled in this fashion. The game uses medium-to-low resolution textures to represent ground cover. Quasi-Realistic: Not accurately scaled in any dimension, but still attempts to represent a real location in the world. Usually employs high-resolution ground cover textures. The scales and textures are chosen to give a sense of the locale that works well in the game environment. NovaLogic's Delta Force series takes this approach. Unrealistic: Everything else! Unrealistic terrain is most commonly used to specifically enhance game play or the backstory of the game. Spread Terrain spread is the degree to which areas of the terrain are unique. Terrain is created in units called tiles. The spread is related to these tiles in one of three ways: Infinite: A square terrain region is repeated, or tiled, in all cardinal directions, such that when the player leaves a region to the west, he enters a new copy of the same terrain tile from the east. This continues for as long as the player keeps moving in that one direction. Finite: The terrain tiles are repeated in all directions, but at some point the repetition stops. Untiled: Terrain tiles are not repeated. Freedom Terrain freedom is the measure of how much the player's in-game movements are restricted by the terrain. Terrain freedom is closely coupled with terrain spread. There are really only two degrees of terrain freedom: Closed: Closed terrain limits player movements in all cardinal directions at some point. With closed terrain, at some point after a player has been moving in a particular direction, he cannot continue that way, either because there is a virtual physical barrier or because the program prevents further movement. In any case, the terrain is usually modeled beyond the barrier only as far as the player can see. After that—nothing. Open: Open terrain allows player movement in any direction for as long as the player wants. Some games will warp the player to the "other side" of the world, where he will keep crossing terrain tile copies until he returns to the place he started. Team LRN
  11. Terrain Modeling 367 There are practical considerations that direct our terrain design choices. Many game engines simply aren't capable of handling the distances involved in large-scale terrains or the number of objects required to appropriately populate them. Some game genres aren't suited to open terrains—the player needs to be confined in order to advance the game story as required. Terrain Data When you want to create a high-fidelity terrain model of a real place in the world, you are going to need to get the data from somewhere. If the area in question is small enough, you may be able to go out and gather the information yourself if you're handy with a theodo- lite (a surveyor's tool). You might be able to glean the necessary information from topo- graphic maps. In either case there is a lot of work involved in the data gathering phase alone. You will need accurate distance measurements and altitudes, as well as photos of the ground cover. But don't despair! There are sources for high-resolution terrain information available on the Internet. If you go to http://edcwww.cr.usgs.gov, the Web portal for the United States Geological Survey (USGS; part of the U.S. government), you can find a wealth of terrain data. The data is available in several forms, but the standard form is the DEM (Digital Elevation Model). DEM-formatted data files have the .dem file extension. Another format in use is the DTM (Digital Terrain Model), which uses the .dtm file extension. Finally, a powerful and complex format called SDTS (Spatial Data Transfer Standard) also exists but is not in wide use outside of scientific niches. SDTS files are denoted by the .ddf file extension. In any event, the ground cover information is not included in these various model for- mats, so you'll need to gather that as well. Again, the USGS comes in handy with its satel- lite imagery—some of it taken down to a resolution of less than a meter per image pixel. DEM files provide elevation information for specific coordinates of places on Earth. DEM files can be converted to a format used by game engines called a height map. We won't go into detail about how to use DEM data for your game, but you can use several of the resources listed in the appendixes to locate the data and tools needed. Terrain Modeling There are basically two approaches that 3D game engines use to model terrain in a 3D world. In both cases 3D polygon models represent terrains. In the external method we include the terrain as just another object in the game world. This method offers much freedom of manipulation. You can rotate the terrain model, skew it, and otherwise subject it to all manner of indignities. All 3D engines support this approach. While flexible, it is usually an inefficient way to render complex large terrains. Team LRN
  12. 368 Chapter 12 ■ Terrains The second approach is the internal method, where terrain is rendered by special code in the game engine often called a Terrain Manager. Using the Terrain Manager approach allows game engine programmers to apply specific memory and performance optimiza- tions to the terrain object, because they can discard unnecessary functions that would be available to general-purpose objects. Because of this, Terrain Manager terrains can some- times be made larger and more complex than those created using other approaches. Most 3D engines, like Torque, that use a Terrain Manager also provide terrain generation, manipulation, and editing tools that we can use to create our own terrains. Usually importing height maps is available for terrain generation. Some engines, like Torque, have built-in Terrain Editors that allow the game developer to directly manipulate terrain poly- gons, within constraints, to create the desired hills, valleys, mountains, and canyons. Height Maps Figure 12.2 depicts a height map. As you can see, it's a grayscale image. The 2D coordi- nates of the height-map image map directly to surface coordinates in the game world. The brightness off each of the pixels in the image represents the altitude at that pixel's loca- tion—the brighter the pixel, the higher the elevation. Usually we use an 8-bit per pixel for- mat, which means that 256 discrete elevations can be represented. The concept is an elegant one and not difficult to grasp. If you are familiar with viewing topographic charts and maps, you'll find that height maps have a familiar flavor to them, even though the contour lines are missing. One of the deficiencies of height maps is the res- olution (as you can see in Figure 12.2). To represent a geographic locale that is 1 kilometer square, a height map that represents 1 square meter as a pixel needs 1,000 pixels per side, for a total of 1 million pixels—big, but not too large. If I want to increase the terrain area to cover 16 square kilometers (4 meters per side), then I need to store 16 million pixels. At 8 bits per pixel, that equals about 16MB of data. If we want to model the terrain for an area that is 10 kilo- meters per side, we are looking at 100MB of storage! We can, of course, reduce the terrain resolution— let's say, have a pixel equal 4 square meters in the game world. This would chop those 100MB back to 6.25MB. However, that gain is offset by the fact that our terrain will now be blockier and less realistic. Figure 12.3 shows a terrain model generated from the height map shown in Figure 12.2. In this case MilkShape was used to import the height map and Figure 12.2 A terrain height map. create the terrain object. Team LRN
  13. Terrain Modeling 369 Terrain Cover In the simplest sense, terrain cover refers to all the stuff that you find on the ground, including: ■ grass ■ flowers ■ dirt ■ pebbles ■ rocks ■ trash ■ litter Figure 12.3 A terrain created from a height map. ■ pavement ■ concrete ■ moss ■ sand ■ stone Obviously this is not a comprehensive list, but it does demonstrate the point. We represent the terrain cover with textures. Our options for creating these textures are much like those we considered when we created textures for structures in Chapter 11— and the factors that dictate which way to choose are also similar. It boils down to the ter- rain characteristics in the game that matter to you. We can also mix terrain cover textures in adjacent areas to portray a particular locale. It's a good idea to develop your own library of generic terrain cover for use in various situations. Figure 12.4 illustrates some of the possible varieties of terrain cover. From left to right in the top row you can see grass, sand, and an intermixed sand and grass texture. In the bot- tom row from left to right are dirt, a muddy track, and eroded wet sand. Tiling Unless you are going to create specific terrain cover textures for every square inch of terrain, you will end up tiling your terrain cover at some point. All the issues brought up with tiling in other contexts apply here, such as matching texture edges to get seamless transi- tions and ensuring lighting in the textures is both appropriate and uniform. Additionally, Figure 12.4 Some example terrain textures. Team LRN
  14. 370 Chapter 12 ■ Terrains you should ensure that there are no patterns or marks in the texture that will stand out too much when the texture is repeated. In Figure 12.5 you can see a repeating light pattern that tends to overpower the otherwise pleasing and pastoral scene. (Okay, okay, it would be pastoral if a storm wasn't brewing beyond the, um…Mountains of Evil in the distance. But besides that…) The culprit in this case is the grass texture used, which is shown in Figure 12.6. Notice the area of lighter grass, which is quite noticeably different from the rest of the image. When repeated over and over across large swaths of terrain, that feature detracts from the intended overall effect. We can enhance the image to minimize the problem, per- haps with something like that shown in Figure 12.7. The result is dramatic and the difference is quite obvious, as you can see in Figure 12.8. Now, I confess that the texture could be better, but you have to admit that it is light-years ahead of the first version, shown in Figures 12.5 and 12.6. Creating Terrains Okay, enough talk. Time for some action—let's create some terrain. We'll use the Torque Engine and its internal Terrain Manager to create the terrain, and we'll employ the height- map method using the in- game Terrain Editor. There is another method, direct manip- ulation, that we'll use later in Figure 12.5 A terrain with tiling artifacts. Chapter 18. The Height-Map Method For this section, you will need to fire up Paint Shop Pro. You should be fairly familiar with the basics, so I won't hold your hand too much with respect to PSP Figure 12.6 A texture with Figure 12.7 A texture operations. an undesirable feature. without the undesirable feature. Team LRN
  15. Creating Terrains 371 note The default size for a terrain in Torque (when the squareSize property in a MIS mission file is set to 8) is 65,536 world units (WU). One WU in Torque is equal to one unit in most third-party map editors. A WU is equiva- lent to one scaled inch. 1. Start with a drawing of the contours to create the height-map image. Figure 12.8 The terrain with improved tiled texture. If you have a source for colored contour drawings for a section of land drawn at full scale (1:1), such as shown in Figure 12.9, get one that suits your needs. If not, you can use the images shown here, but in their colored format, which you will find at C:\3DGPAi1\RESOURCES\CH12. Each image has the same name as the figure number used here. 2. Clip out the portion you want and save it as a PNG image, as shown in Figure 12.10. 3. Now you need to do a little noodling over scale and unit numbers. In Torque each terrain square is made of two terrain triangles sized at 256 WU by 256 WU; as mentioned earlier, the default squareSize property in a Torque Figure 12.9 Contour map. mission file equals 8 by default. The terrain has 256 of these squares per side for a total of 65,536 world units (inches) per side. 256 WU 256 squares=65,536 WU (inches) If we convert the units, we get 5,641.3 feet, or 1,664.6 meters (1.034 miles, or 1.6646 kilometers). 65,536 inches 12 inches=5,461.33 feet 1 mile=5,280 feet 5,461.33 feet 5,280 feet per mile=1.034 miles 1 mile=1,609 meters Figure 12.10 Cropped and 1,664.6177 meters 1,609 meters per mile=1.034 miles resized contour map. Team LRN
  16. 372 Chapter 12 ■ Terrains The value 8 (for squareSize) and the value 65,536 (for terrain size) are not acciden- tal; they are powers of 2. This works nicely with our images as well as the software. The size for our height-map image must be 256 pixels by 256 pixels. This means that when the image is stretched to fit our terrain of 65,536 inches by 65,536 inches, each texture pixel (texel) determines the horizontal distance of 256 inches (or 6.504 meters) of terrain. Because each terrain square is 256 WU, each height- map texel is used to determine the height of one terrain square. 256 pixels 256 WU (inches)=65,536 WU (inches) 256 inches 39.37 inches per meter=6.5024 meters 6.5024 meters 256 pixels=1,664.6177 meters=1.664 kilometers=1.034 miles 4. Based on the preceding calculations, we can get the equivalent area in the image— crop the image just inside the line box created in the Figure 12.10 drawing repre- senting 1.034 square miles. 5. Resize the image to 256 by 256 pixels. 6. Save the image as a PNG file to preserve the original colors for the contours. In a moment you will paint over this contour image using gray color values repre- senting the heights of the contour lines. In this case the contours range from an elevation of 410 feet to 485 feet. This information is available from the source of the contour maps. The grayscale can be any sequence of gray RGB values within the 256 colors ranging from 0,0,0 (black) to 255,255,255 (white). 7. Establish your scale, keeping in mind that it's best to have some separation between the incremental values so they can be easily seen as you paint the contours. Examination reveals that there are 16 elevation increments in the contour range of 410 to 485. Divide the 256 colors for the grayscale range by 16, and you will get the values in Table 12.2, which starts at the color (0,0,0) and works up. Now that we have the values, we need to create what Paint Shop Pro calls swatches. We need to make a different swatch for each increment. 8. Make sure that you have the Materials palette visible in Paint Shop Pro by choos- ing View, Palettes, Materials and clicking on the Swatches tab in the Materials frame. 9. Delete any existing swatches by clicking on each one and then clicking on the trash can icon below the swatches. If you think you can keep track of your custom swatches and the ones already there, then you can skip this step. Next we will create a new swatch for our first increment. 1. Click the Create New Swatch button at the bottom of the Swatch frame. 2. Type in a name for your swatch. I suggest you use either the increment number or the elevation value for the name. You could also use both, as in 1-485 for the top- most entry from Table 12.2. Team LRN
  17. Creating Terrains 373 Table 12.2 Elevation RGB Values Elevation RGB Increment 485 240,240,240 1 480 224,224,224 2 475 208,208,208 3 470 192,192,192 4 465 176,176,176 5 460 160,160,160 6 455 144,144,144 7 450 128,128,128 8 445 112,112,112 9 440 96, 96, 96 10 435 80, 80, 80 11 430 64, 64, 64 12 425 48, 48, 48 13 420 32, 32, 32 14 415 16, 16, 16 15 410 0, 0, 0 16 3. The Color dialog box will appear. Here you type in your RGB values, referring to Table 12.2 for your numbers. Click OK to close the dialog box. 4. Repeat steps 1, 2, and 3 for each increment in the table. 5. Now fill in your image following the contour lines as shown in Figure 12.11. Use a combination of the Brush and Fill tools, at your discretion, to complete the task. Notice that in Figure 12.11 the grayscale value is the same at all the edges. This is because we want the edges to match when the terrain repeats itself, if it is tiled— and in this case that's what we will be dealing with. The edges could be different values; you would then just match them at the top and bot- tom or left and right sides. 6. When you have finished the "paint-by-number" process, convert the image to grayscale by choos- ing Image, Grayscale. 7. Save your image as a PNG file. 8. Flip the image around its X-axis—this flips the top with the bottom—by choosing Image, Flip. You should get an image like that in Figure Figure 12.11 Contour map with 12.12. Make sure you save your work. grayscale values. Team LRN
  18. 374 Chapter 12 ■ Terrains Notice the terrace effect in Figure 12.12. If you import this into Torque as is, you will have a set of terraced, or stepped, surfaces. If this is what you want, then you're good to go already. How- ever, let's go a bit farther. 9. Make a copy of the image you created in step 7 to work with. 10. Choose Adjust, Blur, Gaussian Blur to smooth out the edges a bit. Use a radius of four and then save your changes to this new image as a PNG file. You Figure 12.12 Terraced height should get an image much like the one shown in map. Figure 12.13. tip It can be more difficult to locate your original contour features after smoothing with Gaussian Blur. A quick work-around is to try reducing the radius or use the original image unblurred and smooth the terrain in Torque using the Terrain Editor (covered later). A more time-consuming technique (but much more accurate and rewarding) is to create the ter- rain image at a much larger scale and reduce it to 256 by 256. For example, you might try con- structing the image at around 2,048 by 2,048 or 4,096 by 4,096; this means much more painting time, but after reducing the image size again, the blending information is retained (although somewhat smoothed) by the resize algorithms. The resulting terrain is much more accurate than the Gaussian Blur process. This last height-map image is the one you will work with to create the terrain. Next, we will import these images into Torque. 11. Place the images in Torque's C:\3DGPAi1\common\editor\heightscripts folder. If the folder does not already exist, create it. 12. Use the Run fps Demo shortcut to launch Torque. 13. Run any existing mission to which you'd like to add this terrain or choose File, New Mission. 14. Press F11 to open the World and Terrain Editor. 15. Choose Window, Terrain Terraform Editor (as shown in Figure 12.14) to open the Terrain Terraform Editor. 16. On the right side of the screen, in the General Settings area (see Figure 12.15), set Min Figure 12.13 Blurred height map. Terrain Height and Height Range in meters. Team LRN
  19. Creating Terrains 375 The maximum elevation in the terrain we are modeling is to be used for Minimum Terrain Height (the Minimum Terrain Height box is misla- beled in the Editor). You will recall that the highest elevation is 485 feet; this translates to a Minimum Terrain Height value of approximately 148 meters. 485 feet 3.281 feet per meter=147.8208 (148) meters Height Range represents the distance from our lowest to highest elevation. The grayscale color val- ues of our height-map image will be interpolated Figure 12.14 World Editor Window menu with Terrain between these values. We need to calculate the dif- Terraform Editor checked. ference and multiply that by the ratio of highest color number divided by total number of grayscale colors (256) and convert to meters. Clear as mud? 485 feet 410 feet=75 feet 240 256 75 feet=70.3 feet (240 is our highest color number in Table 12.2) 70.3 feet 3.281 feet per meter=21.4 (21) meters 17. Now click the Operation box to roll out the Opera- tion dialog box, as shown in Figure 12.16. 18. Select Bitmap from this dialog box—this brings up a bitmap Load File dialog box, as shown in Figure 12.17. 19. Highlight the image you want translated to a new Figure 12.15 Terraform Editor. terrain and click the Load button. You should find the height-map image you saved earlier in C:\3DGPAi1\common\editor\heightscripts, from Paint Shop Pro. 20. Click the Apply button at the right side of the menu. You will see the terrain change. To relight the scene, choose Edit, Relight Scene. There will be a slight pause in input response while the relight- ing occurs. 21. In the lower left of the screen the overhead map view of the terrain will change to show the con- tours imported from the height-map image. Notice that this image, as depicted in Figure 12.18, has the same orientation as the original one before Figure 12.16 The Operation we flipped it around the X-axis in step 8 of this list. dialog box. Team LRN
  20. 376 Chapter 12 ■ Terrains The white line in the map shows the terrain boundary, representing the extents of your terrain before repeat- ing. In the main 3D view, a green translucent box illustrates this bound- ary, as you can see in Figure 12.19. The terrain boundary is a fixed dimen- sion—you can't change it. Figure 12.20 illustrates where to find the inner red box that represents the mission area. You can change the extents of the mission area boundary by Figure 12.17 The Load File dialog box. using the Mission Editor. 22. Choose File, Save As to save your mis- sion with your own unique name. You should save your new file in the direc- tory C:\3DGPAi1\fps\data\missions. When you save your mission, the terrain data is also saved as a TER file in the C:\3DGPAi1\fps\data\mis- sions directory. If you want, you can also import previously saved TER files rather than re-creating height maps. Figure 12.18 The overhead view. Figure 12.19 The terrain boundary. Figure 12.20 The mission area. Team LRN
Đồng bộ tài khoản