58958_ch09_rev01_lores 1..18

advertisement
Chapter 9
Conclusions
You have reached the final chapter of this book on Microsoft’s DirectX. At this
point you should have a good understanding of DirectX 11 from graphics to
input and audio as well as basic, yet common, math concepts for both 2D and
3D games. Although a lot of information was covered in this book, this marks
only the beginning of the journey into video game development. Creating a
video game is a lot of hard and fulfilling work, and for beginners, understanding
the concepts in this book is an important first step.
In this chapter we will briefly recap what you have learned and discuss the next
steps to take what you’ve learned to the next level. Where to go from here is not
always a trivial choice and, depending on what your passions are, will determine
how you focus your time as you move forward. Each role on a video game
development team takes a level of expertise that often requires a dedicated and
focused individual to master.
Recap
Each chapter in this book served a specific purpose. As you made your way
through this book, the goal was to slowly advance what you know about DirectX
as a whole and especially Direct3D for graphics rendering. In this section we will
briefly recap what you should have taken away from each chapter of this book.
At any point, don’t hesitate to go back and reread a chapter when you feel you
can improve your understanding, because having a firm grasp of the basics
1
2
Chapter 9
n
Conclusions
discussed in this book is important for making it easier to learn more advanced
topics in the future. In fact, it is essential.
Chapters 1 and 2
The purpose of Chapter 1 was to introduce DirectX, specifically DirectX 11, and
the various components that comprise it. This chapter essentially gave an
overview of the technology, both past and present, and the various parts that
make up the SDK. Not all parts of DirectX 11 fit within the scope of this book,
and now that you are finished with this book it might be beneficial to explore
those other areas as well. In this beginner’s book we’ve covered a lot of topics
necessary to understand when starting off with DirectX, but there is a ton of
advanced aspects that DirectX offers developers.
The purpose of Chapter 2 was to quickly introduce you to Direct3D 11 and the
basics of drawing graphics using the API. Chapter 2 focused on the bare basics
of rendering with Direct3D 11 and wrapped up by drawing a simple 2D triangle.
From this chapter, you should have walked away with the following knowledge:
n
How to initialize Direct3D
n
How to create rendering destinations (swap chains and render targets)
n
How to clear the color buffer of the main rendering target
n
How to draw simple geometry to the screen
n
How to properly release DirectX objects from memory
The first two chapters are largely meant for readers starting out with graphics
programming in DirectX 11. Readers with experience with previous versions of
DirectX, especially DirectX 10, will find these chapters to be a brief recap of what
they should already generally know. Remember, DirectX 11 is very close to
DirectX 10 in many areas, so those with experience with DirectX 10 should have
a leg up on learning DirectX 11. Readers coming from DirectX 9 and later will
have quite an adjustment to make, but this adjustment is definitely for the better,
as DirectX 10 and 11 are very friendly to work with.
Chapters 3 and 4
The purpose of Chapter 3 was to dive a little deeper into rendering with
Direct3D 11 by focusing more on 2D concepts. This was done to give those new
Recap
to DirectX a much more manageable stepping stone to learning the graphics
API, while also providing a necessary foundation for rendering with DirectX.
Chapter 3 differs from Chapter 2 in that it is more focused on geometry and
texture mapping. This separation was done not only to make each chapter more
manageable in size, but also to split the focus from the two extremes of basic
rendering (i.e., learning to get something drawn and learning to expand that
knowledge with textures). Chapters 2 and 3 represent two different levels of skill
when it comes to rendering simple shapes. Readers should have walked away
from Chapter 3 with the following knowledge:
n
How to create custom vertex layouts and structures
n
How to render geometry
n
How to perform texture mapping
n
How to create and utilize vertex and pixel shaders
Text and strings are important elements in any video game, but unlike past
versions of DirectX, such as DirectX 9, text rendering support in the API no
longer exists, and it is up to the developers to write their own text system. The
purpose of Chapter 4 was to show you how to draw text in Direct3D 11 using a
very simple method of generating the geometry and texture coordinates that
make up the strings of text. Although this system is fairly simple, more advanced
and efficient systems would require more skill than you would have obtained
this early in the book; therefore the simple system was introduced to give you a
start with the topic.
Chapter 4 was directly influenced by the information provided in Chapter 3.
You should have walked away from Chapter 4 with the following knowledge:
n
How to generate simple geometry for the purpose of drawing strings of
text
n
How to generate texture coordinates based on the region of the texture
you wish to use (letter of the text) and use this to build strings of text
Chapter 5
The purpose of Chapter 5 was to introduce you to input detection and response
for keyboards, mice, and Xbox game controllers (which work as USB controllers
3
4
Chapter 9
n
Conclusions
on the PC). Input in some form—even exiting the application via the Escape
key—is important to games and demos. Covering input early on could only
benefit you, since none of the graphics-related topics of later chapters had any
bearing on a chapter dedicated to input. You should have walked away from
Chapter 5 with the following knowledge:
n
An understanding of DirectInput
n
The ability to detect input from keyboards
n
The ability to detect input from mice
n
The ability to use Xbox 360 game controllers as input devices
Chapter 6
No book on games or graphics programming can afford not to cover at least the
basics of the mathematics important to the field of game development. Although
math is a huge topic in which you would benefit from formal education, there
are some topics that cannot be left out of a book of this nature, especially a book
targeted toward beginners.
The purpose of Chapter 6 is to give you a basic overview of the various math
concepts that are popular in video games and would be necessary for this book.
Although you do not need a lot of previous experience with the math topics in
this chapter to follow along, everyone needs some exposure and explanation to
help them understand what is being performed and how they can leverage this
knowledge for their benefit.
Chapter 6 largely covered the math necessary for the 3D-oriented chapters that
followed (Chapters 7 and 8) and also went into more depth of the 2D math
concepts explored in previous chapters. You should have walked away from
Chapter 6 with the following knowledge:
n
An understanding of XNA Math
n
An understanding of vectors and normalized vectors
n
An understanding of matrices
n
An understanding of coordinate spaces
n
An understand of transformations
Recap
Chapter 7
The purpose of Chapter 7 was to go into deeper detail of shaders and effects in
Direct3D 11. This chapter not only examined the new effects but also created
examples of some of the shader types Direct3D 11 supports in order to get you
familiar with creating them. Also, a few common yet straightforward effects
were created in this chapter as examples. You should have walked away from
Chapter 7 with the following knowledge:
n
An understanding of the High Level Shading Language (HLSL)
n
An understanding of effect files
n
An understanding of vertex and pixel shaders
n
An understanding of lighting
n
An understanding of geometry shaders
n
An understanding of the tessellation-based shaders (domain and hull)
n
An understanding of compute shaders
Because Direct3D 10, 11, and presumably higher versions will only use shaders
for graphics rendering, it is highly important to have a firm understanding of the
High Level Shading Language and the nature of shaders in general before
concluding this book.
Chapter 8
The purpose of Chapter 8 was to provide information on loading more
complex 3D models and objects than what was seen in the rest of the book.
3D cameras were also discussed in this chapter, which built off of the math
information discussed in Chapter 6. Throughout this book we’ve touched
upon simple shapes in 2D and 3D form, but this chapter takes it to a whole
new level. Although this is a beginner’s book, we could not leave out the one
topic that every reader will need to learn from this book: the ability to draw
models.
This chapter is important for a number of reasons. First, it shows you how to
create complex 3D models, which allows you to begin creating 3D objects and
environments that you commonly see in the 3D games that you play. Secondly,
it discusses how to create cameras in a 3D environment. Rendering characters
5
6
Chapter 9
n
Conclusions
and models can become very advanced when looking at next-generation games
such as Naughty Dog’s Drake’s Uncharted 3, and this book covered the
foundations to get you started. You should have walked away from Chapter 8
with the following knowledge:
n
The ability to render complex 3D models
n
The ability to utilize a 3D camera in a virtual scene
n
The ability to load and utilized models stored in various file formats
n
A basic understanding of how game worlds are represented and
composed
Game Graphics Programming
Graphics is a very important topic for video games and has been for a very long
time. The power of Direct3D 11 comes from its ability to provide nextgeneration effects to 3D games in a way that is efficient and effective. Graphics
is largely a marriage between art (textures, models, etc.) and technology.
There is much more to graphics than the API being used. Graphics optimizations require knowledge of graphics hardware, the ability to profile and find
bottlenecks, and many times some very creative thinking when it comes to
problem solving, where the problem is often about how to get the most out of
what we have. Scene and state management are also topics that will quickly
come up as your scenes become more complex because increasing performance
is often related to what you are not doing (or drawing) rather than what you are
doing. In other words, if you can avoid costly state switches (e.g., instead of
changing textures for every object, draw every object that uses texture A, switch
to texture B, and then draw all objects for texture B and so forth) and only draw
geometry that the user can see, then performance can be increased by reducing
these things as much as possible. Other topics that go with this include
instancing (using fewer draw calls), level of detail (using less geometry for
distant objects), and so much more.
But in addition to drawing geometry, there is also the effects side of graphics
programming, and the fill-rate can have a tremendous impact on performance.
This includes lighting, shadowing, motion-blur, depth-of-field, high dynamic
range rendering, explosions and smoke, and so much more.
Game Programming
There are many resources available to improve your graphics programming
skills. The Game Programming Gems books from Course PTR and ShaderX
books from Charles River Media are excellent resources for learning advanced
graphics programming techniques. To excel at graphics programming, it helps
to have a strong math background. For those without this background, it is often
necessary to invest in some really good math books. These math books do not
necessarily need to be focused on video games, but game math books could help
narrow the focus on the topics most important to an aspiring game developer as
well as present the information in a manner an aspiring game developer can
relate to. The book Mathematics for 3D Game Programming and Computer
Graphics from Charles River Media can be a good reference, depending on your
current level of mathematics skills.
Game Programming
It is a safe bet that your goal in purchasing this book is to learn to make your own
video games. This book marked an important first step toward that goal, and as
you now can see, making even simple video games requires skill and experience.
It is not always easy work, but it can be quite challenging and fulfilling to play
your own creation and to share that experience with other people.
At this juncture you should have enough information to begin writing your own
video games. Realistically, a beginner will not be able to tackle a massively
multiplayer online role-playing game like World of Warcraft (from Activision
Blizzard) or a next-gen shooter like Epic Game’s Bulletstorm, but a game
inspired by Pong, Asteroids, Tic-Tac-Toe, etc. is a great way to get that
experience writing your own games without overburdening yourself. As the
wise saying goes, practice makes perfect, and when learning video game
development, it is best to start small and work your way up.
When creating your own video games, whether it is a hobby, for a portfolio, or
whatever, certain game elements should be present when showcasing your
work. Complete games are composed of menus, high-score screens (if applicable), in-game user interfaces, input, audio, load- and save-game capabilities
(if applicable), polish (steady frame-rate, nice visuals, stable execution), and
special effects to name a few. When putting together a portfolio, it is important
to create games that are as complete as reasonably possible. If you’re starting
7
8
Chapter 9
n
Conclusions
off as a hobbyist or a student, no company will expect “AAA” game titles
within your portfolio, but your games should be complete, stable (bug free),
and reasonably polished.
When programming a video game, you are programming the game logic and
mechanics that create the experience the users are enjoying. This can be
anything from writing code for a death-match game mode in a first-person
shooter to a capture-the-flag game mode, to a single-player game level of an
action game, and so much more. Being able to write simulations efficiently is no
easy task; it takes practice and experience to do it well. But as you gain more
experience, you will find yourself exploring new designs and ideas with more
success and fulfillment. Try not to take on too much, however, because it is easy
to get overwhelmed when you start swimming in the deep end.
This book’s companion website located at www.UltimateGameProgramming.
com (or www.courseptr.com/downloads) has several tutorials on creating video
games, game tools and editors, and game engines. Content for the beginner
level tutorials is being developed, including a series on creating your first
complete 2D game, first complete 3D game, your first level editors, and an
introduction to 2D and 3D game engines. More content is being planned and
developed, so expect this website to grow considerably over time. The book’s
specific URL is www.UltimateGameProgramming.com/BeginningDirectX11.
Or you can use www.courseptr.com/downloads..
In the following section we’ll discuss some games and demos you can create to
move you from a beginner of DirectX to the next level. Although some of these
games might not be the most exciting to play, for a beginner they are very
important to create.
Your First 2D Game
It is often recommended that new game programmers start with a simple game
as a first project, and one popular game to start with is a clone of the classic
Pong, which can be thought of as the “Hello World” of video game programming. At UltimateGameProgramming.com, the first game programming tutorial
is a 2D Pong-inspired game built complete with menus, audio, and keyboard and
game pad input. The overall goals of this tutorial include the following:
Game Programming
n
Learn to create a basic menu system involving game screens
n
Learn basic artificial intelligence in the single-player game mode
n
Implement local two-player support for the multiplayer game mode
n
Design and implement an in-game heads-up display (HUD)
Starting off with a simple game inspired by Pong allows this beginner-level
tutorial to touch upon a few key topics without overwhelming you. This tutorial
is targeted to beginners who have finished this book and are looking to
implement their acquired knowledge into a working video game. A screenshot
of an early version of the tutorial can be seen in Figure 9.1.
Also part of the introduction to the game programming tutorial set is a tutorial on
creating a Tic-Tac-Toe game (Figure 9.2) and a card matching game (Figure 9.3),
each of which reinforces the main topics learned during the first game programming tutorial.
For each of these tutorials in the introductory series, you will need to know how
to perform input with the keyboard and mouse or Xbox 360 game pad (learned
from Chapter 5 of this book), play game audio for sound effects (learned from
Appendix B from the companion website), and how to render 2D graphics
(learned from Chapters 2 and 3 of this book).
Figure 9.1
A screenshot of an early version of the Pong-inspired game programming tutorial.
9
10
Chapter 9
n
Conclusions
Figure 9.2
A screenshot of an early version of the Tic-Tac-Toe-inspired game tutorial.
Figure 9.3
A screenshot of an early version of the card-matching game tutorial.
Following the tutorials in the introductory series will be more 2D themed
tutorials aimed at learning other topics such as online multiplayer game
programming, game programming for multicore machines, and genre-based
game programming (e.g., top-down games, side-scrollers, platforming games,
etc.). These tutorials will increase in difficulty and will introduce more topics
Game Programming
and techniques to aid in learning how to make video games. The goal of these
tutorials is to provide fun exercises for creating games using the knowledge of
DirectX that you have gained in books such as this.
Your First 3D Game
Creating 2D games can be fun, but chances are if you are learning DirectX 11,
your goal is to eventually make 3D video games. Making a 3D video game
presents its own challenges, especially when it comes to the management of the
art content and the techniques used to gain the best performance out of the
application.
When starting out with 3D, it is useful to take simple ideas and bring them into
the 3D realm. For example, creating a spaceship flying through a 3D outer-space
environment while shooting asteroids can be a good first step because:
n
You can keep the player’s avatar (spaceship), asteroids, and environment
(outer space) fairly simple artistically (assuming you are more of a programmer than an artist).
n
You can practice adding particle explosions and other special effects to
enhance the game’s visual for the weapons and the destruction of
asteroids.
n
It allows you to design and implement a simple 3D rendering system
that operates on a higher level than the graphics API itself, which can be
a baby step toward making your first simple game framework (i.e., game
engine).
n
It allows you to figure out how to control the ship in a 3D environment
effectively using common input devices.
n
It allows you to implement more complex camera systems than were
used in the 2D games.
UltimateGameProgramming.com will also have an introduction to 3D game
programming tutorial based around this very concept. The idea is to take what
was done in the introduction tutorials (2D games) and move into the 3D world.
Firing at asteroids allows readers to move into the 3D realm without having to
worry about physics (such as gravity, rag dolls, etc.) and artificial intelligence,
11
12
Chapter 9
n
Conclusions
both of which are challenging to learn individually, let alone together or with
other topics.
Other game tutorials that can make good starting points for learning 3D game
programming include an introduction to first-person shooters, a third-person
platformer, and a simple rail shooter (e.g., Sega’s House of the Dead and Virtual
Cop games).
Your First Multiplayer Game
There is a difference between writing a single-player game, a local multiplayer
game, and an online networked multiplayer game. With a single-player game
there is usually one input device that is polled and responded to each frame as
the game is being played. The same can be said for local multiplayer games
where one or more input device (game pad, etc.) is plugged into a single
machine that both players are interfacing with. This was the main method of
multiplayer gaming before the rise of online networked games.
Networked games can generally be seen in two flavors. First there are LAN (local
area network) games. LAN matches are popular for competitive gaming events
(tournaments), gaming parties and get-togethers, and any time multiple
machines are connected to one another via a network cable but not necessarily
connected to the Internet. Many gamers have played the original Xbox’s Halo
title with their friends by getting together a few Xboxes, a few TVs, and a lot of
pizza and having themselves a LAN party!
The second flavor of networked games includes games played over the Internet
between two or more remote players. This type of gaming session involves many
challenges and obstacles that need to be addressed. Lag, which is the time in
milliseconds it takes for one machine to receive a response from another, is a
huge obstacle to get around. Not only is the frequency with which machines
send messages to one another dynamic, but also the quality of gaming sessions
can be adversely affected by the overall network conditions. And that assumes
the message from one machine actually reaches the other(s).
When starting off with networked multiplayer games over the Internet, one topic
that is sure to come up is predication and smoothing algorithms to keep the
simulation stable and consistent for all players. Usually in LAN matches the lag is
3D Game Engines and Architecture
not an issue because the distance between machines is fairly small, whereas with
the Internet you can be playing with people in other states and countries, not to
mention all of the devices such as routers and stops between you and the other
players. To keep the simulation smooth for all players, games must apply various
techniques to keep everything looking good. This is extremely challenging but
also makes network game programming very interesting and fun to tackle.
There are also issues with network manipulation by players who willingly engage
in cheating or network disruption, bandwidth limitations, the handling of players
who quit or are dropped, migrating between hosts (the game that sets up and
runs the game) if the host leaves the game, and many more topics that make
multiplayer game programming over a network something not to take lightly.
Although a set of multiplayer game programming tutorials has yet to start
development at the time of writing this chapter, there are at least three planned,
with the first being local multiplayer gaming, LAN multiplayer gaming, and
online multiplayer gaming. Each of these tutorials builds off of one another and
scales from beginner to advanced.
3D Game Engines and Architecture
We talked about graphics programming, we talked about game programming,
and then there is game engine development. Generally, the game engine is a
collection of tools and editors used to build games via content and scripts, such
as Epic’s Unreal game engine (see Figure 9.4). These tools can be actual
applications such as light-map compilers, virtual machines, compilers for
scripting systems, and so on, as well as being code such as data structures,
algorithms, helpers and utilities, and much more.
DirectX is not considered a game engine because, although it does have many
base components that are used by games and game engines, DirectX is a
collection of APIs for interfacing with various components such as the graphics
hardware, input devices, audio, and so forth. Also, there is far more that goes
into a game such as memory management, content management and pipeline
tools, multithreading systems, a host of data structures and algorithms, tools
used for automation, and many more tools that are far beyond what DirectX
alone provides. Direct3D, which was the focus of many chapters throughout this
13
14
Chapter 9
n
Conclusions
Figure 9.4
A screenshot from Epic Game’s UDK (Unreal Development Kit).
book, is a rendering application programming interface and not a rendering
engine for the same reasons.
But for those unfamiliar with the term game engine, what is it? A game engine is
a framework that a game is built upon. This framework is usually abstract and
not specific to any one game title, although it can be tailored toward specific
game genres and is usually originally developed around an initial game that
proves the tech. Typically, all game engines, both simple and complex, include
the following components:
n
A rendering system used to draw objects and interfaces
n
Scene management and environment partitioning for non-basic game
worlds
3D Game Engines and Architecture
n
Editors and tools such as level editors, light compilers, collision compilers, content management tools, and much more
n
Character animation systems
n
A system for playing audio and music within games
n
Support for common input devices
More advanced game engines of today can also include additional components
such as the following:
n
Multithreaded support
n
The ability to stream content via a hard drive or disk
n
Advanced material and rendering systems
n
Advanced animation generation systems
n
Powerful scripting languages, compilers, virtual machines, etc.
n
Cinematic systems (cut-scenes)
n
Advanced rendering pipelines for next-generation effects
n
Destructible environments
n
Advanced physics and collision systems
n
Networking systems
n
Auto-update abilities
n
Defenses against cheating
n
And much more
Rendering systems are usually built on top of rending APIs. A rendering system
in a game engine is often a collection of data structures and algorithms that feed
the rendering API data to draw. Think of the two as two systems working
together, where the rendering API draws what it is told to draw and the
rendering system decides what needs to be drawn and how best to present that
data to the rendering API.
Rendering systems (also sometimes referred to as rendering engines) are highlevel tools used to make drawing and data management efficient. For example,
part of a rendering system might be to take a subdivided game world and submit
15
16
Chapter 9
n
Conclusions
only parts of that game world to the rendering API for rendering. By identifying
what the user can see and then only drawing that data, games can increase
performance tremendously. This specific technique falls under the category of
spatial partitioning, practically a necessary evil when drawing terrain, but there
is tons more that modern video games use, some of which include but are not
limited to:
n
Next-gen graphics pipeline (e.g., high dynamic range rendering, etc.)
n
The generation of data (e.g., portals, shadows, occlusion volumes, etc.)
n
Content management for games that stream data
n
State management (reducing graphics API state changes greatly improves
performance)
n
Deferred rendering
n
Effects systems (e.g., shader generation, etc.)
n
And much more
What can be included inside of a game engine seems to have no limits outside of
the scope of what is needed for the game project it is being developed around.
Game engines are a collection of many systems, data structures, algorithms, and
tools that together are used to lay the foundation of a video game and provide
much needed automation. By remaining abstract and not hardcoded to any
specific game, it is possible to reuse game engines across multiple projects. Game
engines such as Epic’s Unreal engine (www.udk.com) do this very well.
Your First Game Engine
Creating a game engine, even a simple one to get started, is no trivial task. If you
don’t approach it with care, you could easily overwhelm yourself with a coding
nightmare. The key to writing a game engine is to not write a video game engine
alone, but instead develop a video game around it. As you develop your game,
you can abstract your code into a higher-level framework as you progress in
development. The game provides a clear end goal to achieve as well as the
roadwork for what needs to be done. Without this end goal or target game to
develop, how would you know what to add or what to focus on? How would you
know when you have completed your task?
Summary
One common mistake beginners make is to try to create a game engine without
creating a game, as if an engine without a game or tech to prove it is its own end
goal. It is easy to get into what is known as feature creep, where you keep adding
features for the sake of adding them without any direction or end goal in mind.
Since the goal of a game engine is to be the foundation of a game, games should
be the driving force, not a bunch of generic features, wrapper classes, and
rendering effects. Tech demos are great, but an actual game is a must.
Creating a “AAA” game engine, on the other hand, takes a tremendous amount
of experience, talent, hard work, and expertise, but we all must start somewhere
in our education. It takes a lot of work and time to obtain such a skill, and
professional game developers should get a lot of credit for the amazing work
they do. Trying to make a video game yourself is a real eyeopener to how serious
game development is.
Summary
DirectX is an amazing tool game developers have at their disposal for developing
software. If you’ve reached this point of the book after working through each
chapter, you will be at a point where the next best step is to go from creating
simple demos to creating your own games. There is much more to explore with
DirectX, and you are encouraged to explore these other areas now that you have
a good handle on the API and how it works.
As a beginner there will be a balancing act between learning more about
graphics programming and gaining experience with game programming, which
go together but are not one and the same. In this book we’ve barely scratched the
surface of graphics programming; there is a mountain of information waiting for
you to learn and explore. There are also the topics of game physics, artificial
intelligence, game engine architecture and design, advanced C++ software
design (or whatever your language of choice is), game design, network game
programming, and so much more. Each of these topics is a huge subject area and
often includes separate job titles performed by teams of experts in their fields.
Becoming a game developer is a long journey but can be a very exciting
experience of learning and exploring. By completing this book, you’ve taken
your first few steps down this rabbit hole that will hopefully lead you to creating
the game experiences you’ve always dreamed of.
17
Download