About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Real-Time 3D Rendering with DirectX and HLSL
A Practical Guide to Graphics Programming
Paul Varcholik
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Visit us on the Web: informit.com/aw
Library of Congress Control Number: 2014933263
Copyright 2014 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
DirectX, Direct3D, MS-DOS, MSDN, Visual Studio, Windows, Windows Phone, Windows Vista, Xbox, and Xbox 360 are registered trademarks of Microsoft Corporation in the United States and/or other countries.
NVIDIA, GeForce, Nsight, and FX Composer are registered trademarks of NVIDIA Corporation in the United States and/or other countries.
Autodesk, Maya and 3ds Max are registered trademarks of Autodesk, Inc. in the United States and/or other countries.
Rendermonkey is a trademark of Advanced Micro Devices, Inc.
OpenGL is a registered trademark of Silicon Graphics, Inc. in the United States and/or other countries worldwide.
StarCraft and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the United States and/or other countries.
COLLADA is a trademark of the Khronos Group Inc.
Photoshop is a registered trademark of Adobe Systems Incorporated in the United States and/or other countries.
Steam is a registered trademark of Valve Corporation.
Terragen is a trademark of Planetside Software.
Unreal Development Kit and UDK are trademarks or registered trademarks of Epic Games, Inc. in the United States and elswhere.
Unity Software is a copyright of Unity Technologies.
All other trademarks are the property of their respective owners.
ISBN-13: 978-0-321-96272-0
ISBN-10: 0-321-96272-9
Text printed in the United States on recycled paper at R.R. Donnelley in Crawfordsville, Indiana.
First printing: April 2014
Editor-in-Chief
Mark Taub
Executive Editor
Laura Lewin
Development Editor
Songlin Qiu
Managing Editor
Kristy Hart
Senior Project Editor
Lori Lyons
Copy Editor
Krista Hansing Editorial
Services, Inc.
Indexer
Tim Wright
Proofreader
Debbie Williams
Technical Reviewers
Michael Gourlay
Joel Martinez
Budirijanto Purnomo
Editorial Assistant
Olivia Basegio
Cover Designer
Chuti Prasertsith
Senior Compositor
Gloria Schurick
Praise for Real-Time 3D Rendering with DirectX and HLSL
I designed and taught the technical curriculum at UCFs FIEA graduate program and was never satisfied with textbooks available for graphics programming. I wish I had Paul Varcholiks book then; it would make the list now.
Michael Gourlay, Principal Development Lead, Microsoft
Modern 3D rendering is a surprisingly deep topic; one that spans several different areas. Many books only focus on one specific aspect of rendering, such as shaders, but leave other aspects with little or no discussion. Real-Time 3D Rendering with DirectX and HLSL takes the approach of giving you a full understanding of what a modern rendering application consists of, from one end of the pipeline to the other.
Joel Martinez, Software Engineer, Xamarin
This practical book will take you on a journey of developing a modern 3D rendering engine through step-by-step code examples. I highly recommend this well-written book for anyone who wants to learn the necessary graphics techniques involved in developing a 3D rendering engine using the latest Direct3D.
Budirijanto Purnomo, GPU Developer Tools Lead, Advanced Micro Devices, Inc.
A great tour of the modern DirectX landscape, with a heavy emphasis on authoring HLSL shaders for common game rendering techniques for C++ developers.
Chuck Walbourn, Senior Design Engineer, Microsoft
Contents-at-a-Glance
Contents
Acknowledgments
I would like to thank the many people who helped make this book possible. First, to the wonderful team at Pearson, especially Laura Lewin, Olivia Basegio, and Songlin Qiu. You have made this a truly enjoyable experience.
Next, to my technical reviewers, Joel Martinez, Dr. Michael Gourlay, and Budi Purnomo, for your time and expert advice. Your insights have made this book so much better. A special thanks to Michael Gourlay, who contributed the code for the Runtime Type Information (RTTI) and Factory discussions.