Introduction

Graphics programming is the magic behind video games, film, and scientific simulation. Every explosion, dust particle, and lens flare you see on a computer screen is processed through a graphics card. In addition, because modern operating systems use the graphics processing unit (GPU) to draw their content, every pixel you see is rendered through the GPU and through software developed by a graphics programmer. It’s a broad topic, but one that has traditionally been the province of a select few. Even to experienced software developers, rendering is often considered a dark art, full of complex mathematics and esoteric tools. Furthermore, the rapid pace of advancement makes modern graphics programming a moving target, and establishing a foothold can be difficult.

That’s where this book comes in. In these pages, you’ll find an introduction to real-time 3D rendering. I’ve presented this material in a straightforward and practical way, but it doesn’t shy away from more complex topics. Indeed, this book takes you far beyond drawing simple objects to the screen and introduces intermediate and advanced subjects in modern rendering. It is my sincere wish that you find the material in this book approachable, applicable, and up-to-date with modern graphics techniques.

Intended Audience

This book is intended for experienced software engineers new to graphics programming. The text often uses terminology from the video game industry, but you need not be a game developer to make use of this book. Indeed, the topic of modern rendering reaches well beyond video games and is becoming ever more pervasive in a variety of software-related fields. Regardless of the specific type of software you develop, if you are interested in learning about modern rendering, this book is for you.

This text also assists existing graphics programmers who are new to DirectX or who are familiar with an older version of the library. We cover DirectX, and the library has seen major changes over the last few years. This book also applies to students, hobbyists, and technical artists interested in real-time rendering.

If you are new to programming, not specifically graphics programming, this book might not be what you’re looking for. In particular, Part III, “Rendering with DirectX,” develops a C++ rendering engine and expects a familiarity with that language.

Why This Book?

Several excellent books on the market explore graphics programming. However, most of these texts focus on only one area: either shader programming or the rendering API (such as DirectX or OpenGL). Mention of the other topic, the other side of the same coin, is often given short shrift—perhaps just a chapter or two.

Modern rendering doesn’t exist without shaders, but shaders aren’t executed without an underlying graphics application. I know of few books that incorporate both topics in a thorough, integrated fashion, nor one that balances introductory material with intermediate and advanced topics. A sticking point with many books is that they are either so novice that they leave the reader wanting or so advanced that even experienced software engineers have trouble absorbing the material.

You can also find a number of good books on general-purpose game or engine programming. These texts often include material on graphics programming or approaches to organizing 3D models and materials. But these books often have such a broad scope that rendering gets lost in the pages.

The approaches I’ve mentioned are all valid, and, again, you can find many wonderful books on the market. Yet I’m seeing a gap where an experienced developer who wants to tackle graphics programming is missing a text that offers a full, focused treatment of rendering from both the CPU and GPU sides of the topic. This book aims to fill this gap.

How This Book Is Organized

This book is organized into four parts:

Image Part I, “An Introduction to 3D Rendering,” provides an introduction to graphics programming. It includes a discussion about the history of DirectX up to version 11.1 (the version we’re using in this book) and looks at the Direct3D graphics pipeline. Chapter 2 includes a primer on 3D math, along with a detailed look at the DirectX Math API. If you are already familiar with linear algebra and 3D mathematics, you might consider skipping or skimming Chapter 2. However, I encourage you to read the section on DirectX Math (Microsoft’s latest revision of an impressive SIMD-friendly math library focused on graphics-related mathematics). Part I ends with an exploration of best-of-breed tools for authoring and debugging shaders and graphics applications.

Image Part II, “Shader Authoring with HLSL,” is all about shaders and programming using the High-Level Shader Language (HLSL). This section begins with the most introductory vertex and pixel shaders and a discussion of semantics and annotations. Chapter 5 examines texture mapping and texture filtering and wrapping modes. Chapter 6 introduces basic lighting models, including ambient lighting, diffuse (Lambert) lighting, and specular highlighting. Chapter 7 details point lights, spot lights, and multiple lights. In Chapter 8, you write shaders involving cube maps, including shaders for skyboxes and environment mapping. Part II concludes with a potpourri of shaders for fog, color blending, normal mapping, and displacement mapping.

Image In Part III, Rendering with DirectX,” we discuss the application side of the house. Throughout this section, you develop a C++ rendering engine and incorporate the shaders you authored in Part II. Chapters 1014 introduce the core components of the engine: the game loop, time, components, and Windows and DirectX initialization. We also cover mouse and keyboard input, cameras, and text rendering. In Chapter 15, you dive into the topic of 3D models: asset loading and model rendering. And in Chapter 16, you develop a flexible effect and material system to integrate your shaders. Part III ends with a chapter on CPU-side structures for directional, point, and spot lights.

Image Part IV, “Intermediate-Level Rendering Topics,” raises the bar a bit and moves to intermediate-level rendering topics. The section begins with a discussion of post-processing techniques (effects typically applied to the entire scene after its initial rendering). This includes shaders for color filtering, Gaussian blurring, bloom, and distortion mapping. In Chapter 19, you implement systems for projective texture mapping and shadow mapping. Then in Chapter 20, you develop a skeletal animation system for importing and rendering animated models. Chapter 21 details geometry and tessellation shaders; you implement a point sprite shader and explore hardware tessellation, a powerful addition to the DirectX 11 graphics pipeline. The book ends with a survey of additional topics in modern rendering, including rendering optimization, deferred rendering, global illumination, compute shaders, and data-driven engine architecture.

Prerequisites

This book has no expectation that you are already a game or graphics developer, nor does it expect you to be fluent in 3D mathematics. It simply requires you to be interested in graphics programming and already be familiar with the C++ programming language. If you are an experienced programmer but you are coming from a different language, you may have no trouble with the material in Parts III and IV. However, there is no concerted effort to discuss C++ syntax.

Furthermore, all code samples are provided for the Microsoft Windows operating system and are packaged for Visual Studio 2012 or 2013. These samples require a graphics card that supports (at least) Shader Model 4. Some of the samples (particularly the demonstrations on compute shaders and tessellation) require a graphics card that supports Shader Model 5.

Companion Website

This book has a companion website at http://www.varcholik.org/. There you’ll find all code samples and errata, along with a forum for questions and discussion about the book.

Conventions in This Book

This book uses a number of conventions for source code, notes, and warnings.


Note

When something needs additional explanation, it is called out in a “note” that looks like this.



Warning: Warnings Look Like This

A “warning” points out something that might not be obvious and could cause problems if you did not know about it.


When code appears inside the text, it looks like this.

You will also find exercises at the end of Chapters 322 (all but the first two chapters). These exercises reinforce the material discussed in the text and encourage you to experiment.

..................Content has been hidden....................

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