
Introduction to 3D Game Programming with DirectX® 12 LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY By purchasing or using this book (the “Work”), you agree that this license grants permission to use the contents contained herein, but does not give you the right of ownership to any of the textual content in the book or ownership to any of the information or products contained in it. This license does not permit uploading of the Work onto the Internet or on a network (of any kind) without the written consent of the Publisher. Duplication or dissemination of any text, code, simulations, images, etc. contained herein is limited to and subject to licensing terms for the respective products, and permission must be obtained from the Publisher or the owner of the content, etc., in order to reproduce or network any portion of the textual material (in any media) that is contained in the Work. MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in the creation, writing, or production of the companion disc, accompanying algorithms, code, or computer programs (“the software”), and any accompanying Web site or software of the Work, cannot and do not warrant the performance or results that might be obtained by using the contents of the Work. The author, developers, and the Publisher have used their best efforts to insure the accuracy and functionality of the textual material and/or programs contained in this package; we, however, make no warranty of any kind, express or implied, regarding the performance of these contents or programs. The Work is sold “as is” without warranty (except for defective materials used in manufacturing the book or due to faulty workmanship). The author, developers, and the publisher of any accompanying content, and anyone involved in the composition, production, and manufacturing of this work will not be liable for damages of any kind arising out of the use of (or the inability to use) the algorithms, source code, computer programs, or textual material contained in this publication. This includes, but is not limited to, loss of revenue or profi t, or other incidental, physical, or consequential damages arising out of the use of this Work. The sole remedy in the event of a claim of any kind is expressly limited to replacement of the book, and only at the discretion of the Publisher. The use of “implied warranty” and certain “exclusions” vary from state to state, and might not apply to the purchaser of this product. Companion disc fi les are available for download from the publisher by writing to info@ merclearning.com. Introduction to 3D Game Programming with DirectX® 12 Frank D. Luna MERCURY LEARNING AND INFORMATION Dulles, Virginia Boston, Massachusetts New Delhi Copyright ©2016 by MERCURY LEARNING AND INFORMATION LLC. All rights reserved. This publication, portions of it, or any accompanying software may not be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means, media, electronic display or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning, without prior permission in writing from the publisher. Publisher: David Pallai MERCURY LEARNING AND INFORMATION 22841 Quicksilver Drive Dulles, VA 20166 [email protected] www.merclearning.com (800) 232-0223 Frank D. Luna. Introduction to 3D GAME PROGRAMMING WITH DIRECTX 12 ISBN: 978-1-942270-06-5 The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others. Library of Congress Control Number: 2015957713 161718321 This book is printed on acid-free paper. Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc. For additional information, please contact the Customer Service Dept. at 800-232-0223(toll free). All of our titles are available in digital format at authorcloudware.com and other digital vendors. Companion fi les for this title are available by contacting [email protected]. The sole obligation of MERCURY LEARNING AND INFORMATION to the purchaser is to replace the book or disc, based on defective materials or faulty workmanship, but not based on the operation or functionality of the product. To my nieces and nephews, Marrick, Hans, Max, Anna, Augustus, Presley, and Elyse CONTENTS Dedication v Acknowledgments xxii Introduction xxv Intended Audience xxvi Prerequisites xxvi Required Development Tools and Hardware xxvii Using the DirectX SDK Documentation and SDK Samples xxvii Clarity xxix Sample Programs and Online Supplements xxix Demo Project Setup in Visual Studio 2010 xxix Download the Book’s Source Code xxx Create a Win32 Project xxx Linking the DirectX Libraries xxxi Adding the Source Code and Building the Project xxxii PART I MATHEMATICAL PREREQUISITES Chapter 1 Vector Algebra 3 1.1 Vectors 4 1.1.1 Vectors and Coordinate Systems 5 1.1.2 Left-Handed Versus Right-Handed Coordinate Systems 6 1.1.3 Basic Vector Operations 7 1.2 Length and Unit Vectors 9 1.3 The Dot Product 10 1.3.1 Orthogonalization 13 1.4 The Cross Product 14 1.4.1 Pseudo 2D Cross Product 16 1.4.2 Orthogonalization with the Cross Product 16 viii INTRODUCTION TO 3D GAME PROGRAMMING WITH DIRECTX® 12 1.5 Points 17 1.6 DirectX Math Vectors 18 1.6.1 Vector Types 19 1.6.2 Loading and Storage Methods 21 1.6.3 Parameter Passing 21 1.6.4 Constant Vectors 23 1.6.5 Overloaded Operators 24 1.6.6 Miscellaneous 24 1.6.7 Setter Functions 25 1.6.8 Vector Functions 26 1.6.9 Floating-Point Error 30 1.7 Summary 31 1.8 Exercises 33 Chapter 2 Matrix Algebra 37 2.1 Defi nition 38 2.2 Matrix Multiplication 40 2.2.1 Defi nition 40 2.2.2 Vector-Matrix Multiplication 41 2.2.3 Associativity 42 2.3 The Transpose of a Matrix 42 2.4 The Identity Matrix 43 2.5 The Determinant of a Matrix 44 2.5.1 Matrix Minors 45 2.5.2 Defi nition 45 2.6 The Adjoint of a Matrix 47 2.7 The Inverse of a Matrix 47 2.8 DirectX Math Matrices 49 2.8.1 Matrix Types 50 2.8.2 Matrix Functions 52 2.8.3 DirectX Math Matrix Sample Program 53 2.9 Summary 54 2.10 Exercises 55 Chapter 3 Transformations 59 3.1 Linear Transformations 60 3.1.1 Defi nition 60 3.1.2 Matrix Representation 60 3.1.3 Scaling 61 3.1.4 Rotation 63 CONTENTS ix 3.2 Affi ne Transformations 66 3.2.1 Homogeneous Coordinates 66 3.2.2 Defi nition and Matrix Representation 67 3.2.3 Translation 67 3.2.4 Affi ne Matrices for Scaling and Rotation 70 3.2.5 Geometric Interpretation of an Affi ne Transformation Matrix 70 3.3 Composition of Transformations 72 3.4 Change of Coordinate Transformations 73 3.4.1 Vectors 74 3.4.2 Points 74 3.4.3 Matrix Representation 75 3.4.4 Associativity and Change of Coordinate Matrices 76 3.4.5 Inverses and Change of Coordinate Matrices 77 3.5 Transformation Matrix versus Change of Coordinate Matrix 78 3.6 DirectX Math Transformation Functions 79 3.7 Summary 80 3.8 Exercises 82 PART II DIRECT 3D FOUNDATIONS Chapter 4 Direct3D Initialization 89 4.1 Preliminaries 90 4.1.1 Direct3D 12 Overview 90 4.1.2 COM 90 4.1.3 Textures Formats 91 4.1.4 The Swap Chain and Page Flipping 93 4.1.5 Depth Buffering 93 4.1.6 Resources and Descriptors 96 4.1.7 Multisampling Theory 98 4.1.8 Multisampling in Direct3D 99 4.1.9 Feature Levels 101 4.1.10 DirectX Graphics Infrastructure 101 4.1.11 Checking Feature Support 105 4.1.12 Residency 107 4.2 CPU/GPU Interaction 107 4.2.1 The Command Queue and Command Lists 108 4.2.2 CPU/GPU Synchronization 112 x INTRODUCTION TO 3D GAME PROGRAMMING WITH DIRECTX® 12 4.2.3 Resource Transitions 114 4.2.4 Multithreading with Commands 116 4.3 Initializing Direct3D 116 4.3.1 Create the Device 117 4.3.2 Create the Fence and Descriptor Sizes 118 4.3.3 Check 4X MSAA Quality Support 119 4.3.4 Create Command Queue and Command List 119 4.3.5 Describe and Create the Swap Chain 120 4.3.6 Create the Descriptor Heaps 122 4.3.7 Create the Render Target View 123 4.3.8 Create the Depth/Stencil Buffer and View 125 4.3.9 Set the Viewport 129 4.3.10 Set the Scissor Rectangles 131 4.4 Timing and Animation 131 4.4.1 The Performance Timer 132 4.4.2 Game Timer Class 133 4.4.3 Time Elapsed Between Frames 134 4.4.4 Total Time 136 4.5 The Demo Application Framework 139 4.5.1 D3DApp 139 4.5.2 Non-Framework Methods 142 4.5.3 Framework Methods 143 4.5.4 Frame Statistics 145 4.5.5 The Message Handler 146 4.5.6 The “Init Direct3D” Demo 149 4.6 Debugging Direct3D Applications 153 4.7 Summary 155 Chapter 5 The Rendering Pipeline 159 5.1 The 3D Illusion 160 5.2 Model Representation 162 5.3 Basic Computer Color 163 5.3.1 Color Operations 164 5.3.2 128-Bit Color 165 5.3.3 32-Bit Color 165 5.4 Overview of the Rendering Pipeline 167 5.5 The Input Assembler Stage 168 5.5.1 Vertices 168 5.5.2 Primitive Topology 169 5.5.2.1 Point List 170 CONTENTS xi 5.5.2.2 Line Strip 170 5.5.2.3 Line List 170 5.5.2.4 Triangle Strip 170 5.5.2.5 Triangle List 171 5.5.2.6 Primitives with Adjacency 171 5.5.2.7 Control Point Patch List 172 5.5.3 Indices 172 5.6 The Vertex Shader Stage 175 5.6.1 Local Space and World Space 175 5.6.2 View Space 179 5.6.3 Projection and Homogeneous Clip Space 182 5.6.3.1 Defi ning a Frustum 183 5.6.3.2 Projecting Vertices 184 5.6.3.3 Normalized Device Coordinates (NDC) 185 5.6.3.4 Writing the Projection Equations with a Matrix 186 5.6.3.5 Normalized Depth Value 187 5.6.3.6 XMMatrixPerspectiveFovLH
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages858 Page
-
File Size-