23,30 €
XNA is a very powerful API using which it's easy to make great games, especially when you have dazzling 3D effects. This book will put you on course to implement the same 3D graphics used in professional games to make your games shine, and get those gamers addicted! If you think 3D graphics is something that limits your games, then this book is for you.
3D Graphics with XNA Game Studio 4.0 is a step by step companion to implement the effects used in professional 3D games in your XNA games. By the time you're done with this book your games would have eye-catching visuals and 3D effects.
The one thing that can make or break a game is its appearance; players will mostly be attracted to a game if it looks good. With this book you will create your 3D objects and models and make them look more interesting by using shadowing and lighting techniques, and make them move in nasty ways using animation. Want to create realistic terrians for your games? Need some place for your 3D models to engage in battle? This book will enable you to do all that and more, by walking you through the implementation of numerous effects and graphics techniques used in professional games so that you can make them look great.
This book is designed as a step-by-step tutorial that can be read through from beginning to end, with each chapter building on the last. Each section, however, can also be used as a reference for implementing various camera models, special effects, etc. The chapters are filled with illustrations, screenshots, and example code, and each chapter is based around the creation of one or more example projects. By the end of the first chapter you will have created the framework that is used and improved upon for the rest of the book, and by the end of the book you will have implemented dozens of special effects, camera types, lighting models and more using that framework.
This book is mainly written for those who are familiar with object oriented programming and C# and who are interested in taking 3D graphics of their XNA games to the next level. This book will be useful as learning material for those who are new to graphics and for those who are looking to expand their toolset. Also, it can be used by game developers looking for an implementation guide or reference for effects or techniques they are already familiar with.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 262
Veröffentlichungsjahr: 2010
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2010
Production Reference: 1071210
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849690-04-1
www.packtpub.com
Cover Image by Charwak A (<[email protected]>)
Author
Sean James
Reviewers
Zhenyu George Li
Cătălin Zima-Zegreanu
Acquisition Editor
David Barnes
Development Editor
Tariq Rakhange
Technical Editor
Namita Sahni
Copy Editor
Laxmi Subramanian
Indexers
Monica Ajmera Mehta
Rekha Nair
Editorial Team Leader
Aditya Belpathak
Project Team Leader
Ashwin Shetty
Project Coordinator
Poorvi Nair
Proofreader
Lynda Sliwoski
Graphics
Geetanjali Sawant
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
Sean James is a computer science student who has been programming for many years. He started with web designing, learning HTML, PHP, JavaScript, and so on. Since then he has created many websites including his personal XNA and game development focused blog, www.innovativegames.net. In addition to web designing, he has interests in desktop software development and development for mobile devices such as Android, Windows Mobile, and Zune. However, his passion is for game development with DirectX, OpenGL, and XNA. Sean James lives in Claremont, CA with his family and two dogs.
I would like to thank my family and friends who supported me throughout the writing of this book, and all the people at Packt Publishing who worked hard on the book to support me. I would also like to thank the XNA community for providing such amazing resources, without which this book would not have been possible.
Zhenyu George Li has been working as a software engineer in the game industry for more than ten years. In his early years, George really enjoyed playing video games and dreamed to be a game developer, so he started learning Turbo C 3D programming and DirectX6 in 1998. George's article series, The Road to Game Development – DirectX Programming with C++ Builder, was published in the magazine Computer Programming Techniques and Maintenance in China in 2000, and George won the magazine's Best Writer prize of the year. After moving to Canada in 2001, George has been working for some companies on several game titles and tools such as CT Baseball (Taiwan), The Bigs2, Dead Rising 2, online poker games, Heroes of Mythology, Battle of Britain, and Avatar XNA skinned Model Animation Engine. As a video game developer, George has accumulated ample knowledge and experience in computer graphics, game play, game frontend and UI, as well as game engine and tools development.
The first time George used Microsoft XNA in 2005, he realized that XNA had great potential for developers, educators, and learners because of its easy-to-learn programming language, C#, and multi-platform support. In 2007, George's book XNA PC and Xbox360 C# Game Programming was published in Taiwan and promoted by Microsoft Taiwan. George was also invited to translate the book Game Programming Gems 4 that was published in Taiwan in 2006.
I am thankful to Pat McGee for helping me with the Avatar XNA Skinned Mesh Animation Engine project and referring the opportunity of being the technical reviewer of 3D Graphics with XNA Game Studio 4.0. I also want to appreciate Charles Yeh and Dr. Wyn Roberts' support on my works and publications.
Cătălin Zima-Zegreanu has been coding games and graphics as a hobby for over eight years, and is planning on continuing to do so. Starting with Pascal, he continued with OpenGl and DirectX and is now passionately in love with XNA Game Studio.
He got involved with XNA and its community since the first beta version, released back in 2006, and likes to hang around the official Creator's Club Forums, to chime in whenever he feels he can help someone. His activity as well as his articles and samples released for the growing community were rewarded with the Microsoft XNA/DirectX MVP Award. You can follow his activity on his own site (http://catalinzima.com), as well as on "Sgt. Conker" (http://sgtconker.com)—an XNA community site he's managing together with a group of "absolutely fine" men.
I'd like to thank my wife for being a geek. Just like me! :)
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
XNA is a very powerful API using which it's easy to make great games, especially when you have dazzling 3D effects. This book will show you how to implement the same 3D graphics used in professional games to make your games shine, and get those gamers addicted! This book will show you, step-by-step, how to implement the effects used in professional 3D games in your XNA games. Upon reaching the end of the book, you would have built an extensible framework for both basic 3D rendering and advanced effects. The one thing that can make or break a game is its appearance; players will mostly be attracted to a game if it looks good. One of the most common stopping points in an XNA game is its graphics, and many independent developers are not sure of how to implement the graphical effects needed to make great looking games. This book will help you avoid this pitfall, by walking you through the implementation of many common effects and graphics techniques used in professional games so that you can make your games look great.
Chapter 1, Getting Started with 3D, introduces the fundamentals of 3D graphics, including coordinate systems, matrices, and so on, which will be used for the rest of the book. We start by learning some simple model drawing code and finish by building a framework to implement a number of camera types. We also take a look at view frustum culling and how it can speed up our game.
Chapter 2, Introduction to HLSL, continues on the first chapter, explaining the graphics pipeline and shaders. We then look at a number of lighting and texturing effects, expanding on the framework built in Chapter 1 and adding a system that will allows us to draw our models with any effect.
Chapter 3, Advanced Lighting, continues our discussion of lighting, implementing more light types. We then look at several ways to increase the number of lights we can draw in a scene at a time.
Chapter 4, Projection and Shadowing Effects, builds on top of the renderer completed in Chapter 3 by adding two new effects: projected textures and shadow mapping.
Chapter 5, Shader Effects, takes a look at some "shader effects" such as normal mapping and reflections. We build a number of useful effects in this chapter such as a sky box and reflective water effect.
Chapter 6, Billboard and Particle Effects, investigates particle and billboarding effects—two effects that take advantage of 2D textures to create some interesting effects in 3D scenes such as foliage, clouds, and efficient trees and particle systems.
Chapter 7, Environmental Effects, discusses several "environmental" effects such as terrain, randomly "grown" foliage, and more. The chapter finishes by combining many effects created in the book thus far to create a spectacular mountainous terrain scene.
Chapter 8, Advanced Materials and Post Processing, expands on the material system created in the earlier chapter to allow for more advanced material types. It then takes a look at "post processing" effects like blurs, glows, and depth of field.
Chapter 9, Animation, takes a look at several different types of animation, including objects animation, keyframed animation, and skinned animation to introduce movement into our scenes.
All you need for this book is XNA and Visual Studio—the whole list and guide is available at creators.xna.com.
This book is mainly written for those who are familiar with object-oriented programming and C# and who are interested in improving the visual appearance of their XNA games. This book will be useful as a learning material for those who are new to graphics and for those who are looking to expand their toolset. Also, it can be used by game developers looking for an implementation guide or reference for effects or techniques they are already familiar with.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code for this book
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
One thing that all 3D systems hold in common is a coordinate system. Coordinate systems are important because they allow us to represent points in 3D space in a consistent manner as distances from a center point called the origin along a number of axes. You're probably used to the idea of a 2D coordinate system from your math classes in school—the origin was at (0, 0) and the X and Y axes grew to the right and up respectively. A 3D coordinate system is very similar, except for the addition of a third axis labeled the Z-axis. XNA uses what is called a "right-handed" coordinate system, meaning that the X and Y axes grow the way you're used to (to the right and up respectively), and the Z-axis grows "towards" you. If the X and Y axes were placed flat on your computer screen, you can imagine the Z-axis as growing out of the screen towards you.
With this coordinate system, we can define points in space. For example, let's assume that our coordinate system uses meters as units. Say for a moment, we were sitting at the origin (0, 0, 0) and were facing down the negative portion of the Z-axis. If we wanted to note the location of an object sitting five meters in front of us, three meters to the right, on a table one meter tall, we would say that the object was at (3, 1, -5).
Matrices are mathematical structures that are used in 3D graphics to represent transformations—operations performed on a point to move it in some way. The three common transformations are translation (movement), rotation, and scaling (changing size). When a transformation is applied to a model, each vertex in the model is multiplied by the transformation's matrix until the entire model has been transformed.
Matrices can be combined by multiplying them together. It is worth noting that matrix multiplication is done from right to left, so the last matrix to be multiplied will be the first to affect the model and so on. This means that rotating and then moving a model will not have the same effect as moving and then rotating it. Generally, unless you mean to do otherwise, the matrices should be multiplied in the following order: scaling * rotation * transformation.
In the 3D graphics world, there are usually three matrices that must be calculated to draw an object onto the screen: the world, view, and projection matrices. The world matrix is the result of all of our transformation matrices multiplied together. Once this transformation has been applied, the model has moved from what is called "local" or "object space" to "world space". Each model in a scene has a different world matrix, as they all have different locations, orientations, and so on. It is also possible that each "piece" of a model (or mesh) may have its own world matrix. For example, the head and leg of a human model will likely have their own matrices to offset them from the center of the model (its root). When the model is drawn, each mesh has its transformation multiplied by the entire model's world matrix to calculate the final world matrix.
The view matrix is used to transform the scene from world space into view space: the world as seen by the camera. The world matrix for each model is simply multiplied by the view matrix to transform the scene. The projection matrix then transforms the three-dimensional position of each vertex in the scene into the two-dimensional projection of the scene that is drawn onto the screen. When the 3D world/view matrix combination is multiplied by the projection matrix, the scene is flattened out so that it can be drawn onto a 2D screen.
