i
i
i
i
i
i
i
i
2 6
2 6
Naty Hoffman
Computer Graphics in Games
Of all the applications of computer graphics, computer and video games attract
perhaps the most attention. The graphics methods selected for a given game have
a profound effect, not only on the game engine code, but also on the art asset
creation, and even sometimes on the gameplay, or core game mechanics.
Although game graphics rely on the material in all of the preceding chapters,
two chapters are particularly germane. Games need to make highly efcient use of
graphics hardware, so an understandingof the material in Chapter 18 is important.
Of course, games are interactive applications, and, as such, many of the principles
detailed in Chapter 19 apply.
In this chapter, I will detail the specic considerations that apply to graph-
ics in game development, from the platforms on which games run to the game
production process.
26.1 Platforms
Here, I use the term platform to refer to a specic combination of hardware, op-
erating system, and API (application programming interface) for which a game
is designed. Games run on a large variety of platforms, ranging from virtual
machines used for browser-based games to dedicated game consoles using spe-
cialized hardware and APIs.
In the past, it was common for games to be designed for a single platform.
The increasing cost of game development has made this rare; multiplatform game
653
i
i
i
i
i
i
i
i
654 26. Computer Graphics in Games
development is now the norm. The incremental increase in development cost to
support multiple platforms is more than repaid by a potential doubling or tripling
of the customer base.
Some platforms are quite loosely dened. For example, when developing a
game for the Windows PC platform, the developer must account for a very large
variety of possible hardware congurations. Games are even expected to run (and
run well) on PC congurations that did not exist when the game was developed!
This is only possible due to the abstractions afforded by the APIs dening the
Windows platform.
One way in which developers account for wide variance in graphics perfor-
mance is by scaling—adjusting graphics quality in response to system capabil-
ities. This can ensure reasonable performance on low-end systems, while still
achieving competitive visuals on high-performance systems. This adjustment is
sometimes done automatically by proling the system performance, but more of-
ten this control is left in the hands of the user, who can best judge his personal
preferences for quality versus speed. Display resolution is easiest to adjust, fol-
lowed by antialiasing quality. It is also fairly common to offer several quality
levels for visual effects such as shadows and motion blur, including the option of
turning the effect off entirely.
Differences in graphics performance can be so large that some machines may
not run the game at a playable frame rate, even with the lowest quality settings;
for this reason PC game developers publish minimum and recommended machine
specications for each game.
As platforms, game consoles are strictly dened. When developing a game
for, e.g., Nintendo’s Wii console, the developer knows exactly what hardware the
game will run on. If the platform’s hardware implementation is changed (often
done to reduce manufacturing costs), the console manufacturer must ensure that
the new implementation behaves exactly like the previous one, including timing
and performance. This is not to say that the console developer’s task is easy; con-
sole APIs tend to be much less abstract and closer to the underlying hardware.
This gives console development its own set of difculties. In some sense, mul-
tiplatform development (which commonly includes at least two different console
platforms and often Windows as well) is the hardest of all, since the multiplatform
game developer has neither the assurance of a xed platform or the convenience
of a single high-level API.
Browser-based virtual machines such as Adobe Flash are an interesting class
of game platforms. Although such virtual machines run on a wide class of hard-
ware from personal computers to mobile phones, the high degree of abstraction
provided by the virtual machine results in a stable and unied development plat-
i
i
i
i
i
i
i
i
26.2. Limited Resources 655
form. The relative ease of development for these platforms and the huge pool
of potential customers makes them increasingly attractive to game developers.
However, these platforms are dened by the lowest common denominator of the
supported hardware, and virtual machines have lower performance than native
code on any given platform. For these reasons, such platforms are best suited to
games with modest graphics requirements.
Platforms can also be characterized by their openness to development, which
is a business or legal distinction rather than a technical one. For example, Win-
dows is open in the sense that development tools are widely available, and there
are no gatekeepers controlling access to the marketplace of Windows games. Ap-
ple’s iPhone is a somewhat more restricted platform in that all applications need
to pass a certication process and certain classes of applications are banned out-
right. Consoles are the most restrictive game platforms, where access to the de-
velopment tools is tightly controlled. This is opening up somewhat with the in-
troduction of online console game marketplaces, which tend to be more open. A
particularly interesting example is Microsoft’s Xbox LIVE Community Games
service, where the development tools are freely available and the “gatekeeping” is
performed primarily by peer review. Games distributed through this service must
use a virtual machine platform provided by Microsoft for security reasons.
The game platform determines many elements of the game experience. For
example, PC gamers use keyboard and mouse, while console gamers use special-
ized game controllers. Many console games support multiple players on the same
console, either sharing a screen or providing a window for each player. Due to the
difculty of sharing keyboard and mouse, this type of play is not found on PC. A
handheld game system will have a different control scheme than a touch-screen
phone, etc.
Although game platforms vary widely, some common trends can be discerned.
Most platforms have multiple processing cores, divided between general-purpose
(CPU) and graphics-specic (GPU). Performance gains over time are due mostly
to increases in core count; gains in individual core performance are modest. As
GPU cores grow in generality, the lines between GPU and CPU cores are increas-
ingly blurred. Storage capacity tends to increase at a slower rate than processing
power, and communication bandwidth (between cores as well as between each
core and storage) grows at a slower pace still.
26.2 Limited Resources
One of the primary challenges of game graphics is the need to manage multiple
pools of limited resources. Each platform imposes its own constraints on hard-
i
i
i
i
i
i
i
i
656 26. Computer Graphics in Games
ware resources such as processing time, storage, and memory bandwidth. At a
higher level, development resources also need to be managed; there is a xed-size
team of programmers, artists and game designers with limited time to complete
the game, hopefully without working too much overtime! This needs to be taken
into account when deciding which graphics techniques to adopt.
26.2.1 Processing Time
Early game developers only had to worry about budgeting a single processor.
Current game platforms contain multiple CPU and GPU cores. These processors
need to be carefully synchronized to avoid deadlocks or excessive
stalls.
Since the time consumed by a single rendering command is highly variable,
graphics processors are decoupled from the rest of the system via a command
buffer. This buffer acts as a queue; commands are deposited on one end and
the GPU reads rendering commands from the other. Increasing the size of this
buffer decreases the chances of GPU starvation. It is fairly common for games to
buffer an entire frame’s worth of rendering commands before sending them to the
GPU; this guarantees that GPU starvation does not occur. However, this approach
requires reserving enough storage space for two full frame’s worth of commands
(the GPU works on one, while the CPU deposits commands in the other). It
also increases the latency between the user’s input and the display, which can be
problematic for fast-paced games.
Processing budgets are determined by the frame rate, which is the frequency
at which the frame buffer is refreshed with new renderings of the scene. On xed
platforms (such as consoles), the frame rate experienced by the user is essentially
the same one seen by the game developer, so fairly strict frame–rate limits can be
imposed. Most games target a frame rate of 30 frames per second (fps); in games
where response latency is especially important, the target is often 60 fps. On
highly variable platforms (such as PCs), the frame-rate budgets are (by necessity)
dened more loosely.
The required frame rate gives the graphics programmer a xed budget per
frame to work with. In the case of a 30 fps target, the CPU cores have 33 millisec-
onds to gather inputs, process the game logic, perform any physical simulations,
traverse the scene description, and send the rendering commands to the graphics
hardware. In parallel, other tasks such as audio and network processing must be
handled, with their own required response times. While this is happening, the
GPU is typically executing the graphics commands submitted during the previous
frame.
i
i
i
i
i
i
i
i
26.2. Limited Resources 657
In most cases, CPU cores are a homogeneous resource; all cores are the same,
and any of them are equally well suited to a given workload (there are some
exceptions, such as the Cell processor used in Sony’s PLAYSTATION 3 console).
In contrast, GPUs contain a heterogeneous mix of resources, each special-
ized to a certain set of tasks. Some of these resources consist of xed-function
hardware (for triangle rasterization, alpha blending, and texture sampling), and
some are programmable cores. On older GPUs, programmable cores were further
differentiated into vertex and pixel processing cores; newer GPU designs have
unified shader cores which can execute any of the programmable shader types.
Such heterogeneousresources are budgeted separately. Typically, at any point,
only one resource type will be the bottleneck, and the others will have excess ca-
pacity. On the one hand, this is good, since this capacity can be leveraged to
improve visual quality without decreasing performance. On the other hand, it
makes it harder to improve performance, since decreasing usage of any of the
non-bottleneck resources will have no effect. Even decreasing usage of the bot-
tleneck resource may only improve performanceslightly, depending on the degree
of utilization of the “next bottleneck.
26.2.2 Storage
Game platforms, like any modern computing system, possess multi-stage stor-
age hierarchies, with smaller, faster memory types at the top and larger, slower
storage at the bottom. This arrangement is borne of engineering necessity, al-
though it does complicate life for the developer. Most platforms include optical
disc storage, which is extremely slow and is used mostly for delivery. On plat-
forms such as Windows, a lengthy installation process is performed once to move
all data from the optical disc onto the hard drive, which is signicantly faster.
The optical disc is never used again (except as an anti-piracy measure). On con-
sole platforms, this is less common, although it does sometimes happen when a
hard drive is guaranteed to be present, as on Sony’s PLAYSTATION 3 console.
More often, the hard drive (if present) is only used as a cache for the optical
disc.
The next step up the memory hierarchy is RAM, which on many platforms is
divided into general system RAM and VRAM (video RAM) which benets from
a high-speed interface to the graphics hardware. A game level may be too large to
t in RAM, in which case the game developer needs to manage moving the data
in and out of RAM as needed. On platforms such as Windows, virtual memory
is often used for this. On console platforms, custom data streaming and caching
systems are typically employed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.188.238