Terrains Explained To understand terrains in a game developmentcontext, we need to look at the characteristics ofthe terrain we want to model.. Essentially a ter-rain tile is a collecti
Trang 1Then choose Image, Rotate, Free Rotate to get the FreeRotate 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 theselected area 1 full degree to the right (see Figure 11.10)
You should have your rotated area with the selection quee still surrounding it Don't touch anything yet—leavethe selection as it is
mar-Now after having explained the Croptool, I'll show you another way tocrop the image that is sometimesmore convenient than using theCrop tool With the rotated area stillselected, choose Image, Crop toSelection and the image will be cropped for you!
You will then end up with an image as shown inFigure 11.11 suitable for use as a texture
Now compare Figure 11.11 with Figure 11.7and you will see the difference
is not to teach you how to draw, so if you want
to learn more, I encourage you to look into ing some lessons
tak-If you are satisfied with your artistic skills, thenyou 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 toollike Paint Shop Pro You can draw freehand using the mouse or a pen tablet
Sources 357
Figure 11.8 Rectangular
Selection tool icon
Figure 11.9 The Free Rotate dialog box.
Figure 11.10 The rotated woodgrain.
Figure 11.11 The cropped woodgrain
image
Trang 2With 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 Figure11.12 shows examples of textures created using the built-in features of Paint Shop Pro Iencourage 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 payattention to the issue of scale The sizes of the thingswithin an image that is used to make a texture have aparticular relationship to other real-world objects Weare subconsciously aware of many of these relation-ships from our exposure to the world in general andwill notice when the textures are out of proportion tothe items they adorn If it's bad enough the effect cansometimes be similar to the sound of fingernails beingdragged 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 moreappropriately sized, yet may still be a bittoo large Yes, there are some uses forstone blocks having proportions such asthose in house A, but they are rarelyused in bungalow-sized or two-storyhomes, as depicted in the figure.The scale issue can pop up anywhere, as youcan see in Figure 11.14 The texture image inthe corrugated metal bridge surface is probablyabout 10 times larger than is appropriate.Sometimes you might need to redo the texture
to match—other times you can adjust how thetexture is applied to the polygons using themodeling tools My rule of thumb is that if thetexture image size is 64 pixels by 64 pixels orsmaller and needs to be made larger, youshould make a new texture at the larger size.The same goes the other way: If the image size
Chapter 11 ■ Structural Material Textures358
Figure 11.14 Scaling error.
Figure 11.13 Scaling bricks.
Figure 11.12 Example textures.
Trang 3is larger than 64 pixels by 64 pixels and needs to be made smaller, then make a new ture at the smaller size.
tex-Tiling
Many structures have large surfaces with repeating patterns The best way to approachmaking textures for these surfaces is to create one smaller texture that is replicated manytimes 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 thatthe edges of the texture align properly when they meet Figure 11.15 shows this to goodeffect You can see the obvious horizontal as well as the more subtle artifacts in house Awhere the tiled brick textures don't quite line up In house B, where care was taken toensure 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, thistime caused by asymmetric lightingeffects in the texture shading You can seeeach repeated texture tile—its position ismarked by the presence of the darkershaded bricks in a repeated pattern Thiseffect can be quite subtle and difficult todetect in an image viewed in isolation
Figure 11.16 shows the texture used in house B of Figure11.15 Looking at it in isolation, you would be hardpressed to notice the subtly darker shaded bricks
The simplest way to fix up a texture for use as a tiled ture is to copy the left edge, about 5 or 10 pixels wide,mirror the copy horizontally, and then paste the copy onthe right side of the image Do the same for the bottomedge Of course, you can go from top to bottom or right
tex-to left as well The important step is the mirroring
After placing the mirrored edges, spend a little timeblending their inner edges with the interior portions ofthe image
Figure 11.17 shows a stone block texture that is a date for use in a tiling situation
candi-Figure 11.18 shows the texture tiled in a set of four Again,you can see the artifacts caused by the mismatched edges
Tiling 359
Figure 11.15 Tiled brick texture.
Figure 11.17 A stone texture.
Figure 11.16 The brick texture
with asymmetric shading
Trang 4Figure 11.19 shows theleft edge being copied,mirrored, and placed
on the right
Figure 11.20 shows thesame thing happeningwith the bottom edge.Finally, Figure 11.21shows the tiled result
Texture Types
There are far too manytexture types and class-
es of material ances for me to enu-merate them with anysort of thoroughness.Given that, there is amuch smaller set of tex-ture types that arefound over and over innature and man-madestructures
appear-Most of the following textures are types that are used for buildings, bridges, and otherman-made items in a game world
Irregular
Irregular textures tend to have a general disorder andrandom appearance, like that shown in Figure 11.22 Dirtand grass are examples of irregular textures Quite oftenirregular textures are combined with other, differentirregular textures in order to give a weathered or dam-aged appearance to an area or surface
Chapter 11 ■ Structural Material Textures360
Figure 11.18 Poorly tiled stone
Trang 5Rough textures, as shown in Figure 11.23, sometimeshave somewhat the same sense about them as irregulartextures They are often used as tiles on a surface like asidewalk or rough concrete walls
Pebbled
Pebbled textures are another example of textures oftenused for paved surfaces and stone walls Tarmacadampavement is an example of a finely pebbled surface whenviewed from a distance
of about 5 or 6 feet
Figure 11.24 shows amore obvious pebbledtexture that could beused for a wall or deco-rative planter
Woodgrain
Figure 11.25 shows awoodgrain texture thathas many highly variantbundles of lines rang-ing from fine to coarse that run roughly parallel to eachother, sometimes interrupted by swirls and knots Somekinds of stone have similar appearances
Trang 6Metallic textures tend to have a dominant color, with astrong dark shadow that follows the outer contours ofthe metallic object and a bright accent color that runsalong raised surfaces Figure 11.29 shows a texture thatcould 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 tured object Figure 11.30 is such a texture that might bedepicting a bright overhead light reflecting off a window
tex-Plastic
Plastic textures are ilar to metallic textures
sim-in their manner ofshading and highlight-ing Plastic tends tohave more of an oilyappearance to it attimes, so the shadingand highlights are oftenmore sinuous Asshown in Figure 11.31,
Chapter 11 ■ Structural Material Textures362
Trang 7the highlights tend to be less clearly defined than withmetallic 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-worldstructures We saw some of the processing techniques that
we may need to use to prepare our images for use as tures, like color matching and cropping
tex-Some of the areas that can be more problematic whenconsidering 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 whoseopposite edges can be mated together without producing a noticeable seam
Finally, we explored some of the more common texture patterns and characteristics thatare used in games
In the next chapter, we will look at terrains, which are often used to provide that touch ofrealism 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
Moving Right Along 363
Figure 11.31 A plastic texture.
Trang 8This page intentionally left blank
Trang 9Terrains
chapter 12
Many games take place exclusively inside buildings or structures, like tunnels
And many other games involve exclusive outdoor game play Then there aresome 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 groundcover (grass, gravel, sand, and so on) The topography is modeled using a 3D model, andthe 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 developmentcontext, we need to look at the characteristics ofthe terrain we want to model These characteris-tics will drive our need for the data that defines theterrain 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 a3D model that represents the terrain, as depict-
ed in Figure 12.1
Figure 12.1 An untextured terrain tile.
Trang 10When 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
Chapter 12 ■ Terrains366
Table 12.1 Terrain CharacteristicsCharacteristic 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.
Trang 11There are practical considerations that direct our terrain design choices Many gameengines simply aren't capable of handling the distances involved in large-scale terrains orthe number of objects required to appropriately populate them Some game genres aren'tsuited to open terrains—the player needs to be confined in order to advance the gamestory as required.
Terrain Data
When you want to create a high-fidelity terrain model of a real place in the world, you aregoing to need to get the data from somewhere If the area in question is small enough, youmay 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 phasealone You will need accurate distance measurements and altitudes, as well as photos ofthe ground cover
But don't despair! There are sources for high-resolution terrain information available onthe Internet If you go to http://edcwww.cr.usgs.gov, the Web portal for the United StatesGeological Survey (USGS; part of the U.S government), you can find a wealth of terraindata
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 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
for-DEM files provide elevation information for specific coordinates of places on Earth for-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 theresources 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 3Dworld 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 thisapproach While flexible, it is usually an inefficient way to render complex large terrains
Terrain Modeling 367
Trang 12The 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 tions to the terrain object, because they can discard unnecessary functions that would beavailable 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 Usuallyimporting height maps is available for terrain generation Some engines, like Torque, havebuilt-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
optimiza-Height Maps
Figure 12.2 depicts a height map As you can see, it's a grayscale image The 2D nates of the height-map image map directly to surface coordinates in the game world Thebrightness 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
coordi-The concept is an elegant one and not difficult to grasp If you are familiar with viewingtopographic 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 kilometersquare, 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 tocover 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 wewant 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 thegame world This would chop those 100MB back to6.25MB However, that gain is offset by the fact thatour terrain will now be blockier and less realistic.Figure 12.3 shows a terrain model generated fromthe height map shown in Figure 12.2 In this caseMilkShape was used to import the height map andcreate the terrain object
Chapter 12 ■ Terrains368
Figure 12.2 A terrain height map.
Trang 13Terrain Cover
In the simplest sense, terrain cover refers to all the
stuff that you find on the ground, including:
We represent the terrain cover with textures Our options for creating these textures aremuch 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 rain characteristics in the game that matter to you
ter-We can also mix terrain cover textures in adjacent areas to portray a particular locale It's agood 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 inthe 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 terraincover textures for every square inch of terrain,you will end up tiling your terrain cover atsome point All the issues brought up withtiling in other contexts apply here, such asmatching texture edges to get seamless transi-tions and ensuring lighting in the textures isboth appropriate and uniform Additionally,
Trang 14you should ensure that there are no patterns or marks in the texture that will stand outtoo 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 theimage When repeated over and over across large swaths of terrain, that feature detractsfrom 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 forsome action—let's create someterrain We'll use the TorqueEngine and its internal TerrainManager to create the terrain,and we'll employ the height-map method using the in-game Terrain Editor There isanother method, direct manip-ulation, that we'll use later inChapter 18
The Height-Map Method
For this section, you willneed to fire up Paint ShopPro You should be fairlyfamiliar with the basics, so Iwon't hold your hand toomuch with respect to PSPoperations
Chapter 12 ■ Terrains370
Figure 12.5 A terrain with tiling artifacts.
Figure 12.6 A texture with
an undesirable feature
Figure 12.7 A texture
without the undesirable feature
Trang 15One WU in Torque is equal toone unit in most third-partymap editors A WU is equiva-lent to one scaled inch.
1 Start with a drawing ofthe contours to createthe height-map image
If you have a source forcolored 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 shownhere, but in their colored format, which you will find
at C:\3DGPAi1\RESOURCES\CH12 Each image hasthe same name as the figure number used here
2 Clip out the portion you want and save it as a PNGimage, as shown in Figure 12.10
3 Now you need to do a little noodling over scale andunit numbers
In Torque each terrain square is made of two terraintriangles sized at 256 WU by 256 WU; as mentionedearlier, the default squareSize property in a Torquemission file equals 8 by default The terrain has
256 of these squares per side for a total of 65,536world units (inches) per side
1 mile=1,609 meters 1,664.6177 meters ⫼1,609 meters per mile=1.034 miles
Creating Terrains 371
Figure 12.8 The terrain with improved tiled texture.
Figure 12.10 Cropped and
resized contour map
Figure 12.9 Contour map.