1. Trang chủ
  2. » Công Nghệ Thông Tin

Real time rendering tricks and techniques in directx

764 47 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 764
Dung lượng 6,42 MB

Nội dung

Real-Time Rendering Tricks and Techniques in DirectX by Kelly Dempski ISBN:1931841276 Premier Press © 2002 (821 pages) Provides a clear path to detailing frequently requested DirectX features CD Content Table of Contents Back Cover Comments Table of Contents Real-Time Rendering Tricks and Techniques in DirectX Foreword Introduction Part I - First Things First Chapter - 3D Graphics: A Historical Perspective Chapter - A Refresher Course in Vectors Chapter - A Refresher Course in Matrices Chapter - A Look at Colors and Lighting Chapter - A Look at the Graphics Pipeline Part II - Building the Sandbox Chapter - Setting Up the Environment and Simple Win32 App Chapter - Creating and Managing the Direct3D Device Part III - Let the Rendering Begin Chapter - Everything Starts with the Vertex Chapter - Using Transformations Chapter 10 - From Vertices to Geometry Chapter 11 - Fixed Function Lighting Chapter 12 - Introduction to Textures Chapter 13 - Texture Stage States Chapter 14 - Depth Testing and Alpha Blending Part IV - Shaders Chapter 15 - Vertex Shaders Chapter 16 - Pixel Shaders Part V - Vertex Shader Techniques Chapter 17 - Using Shaders with Meshes Chapter 18 - Simple and Complex Geometric Manipulation with Vertex Shaders Chapter 19 - Billboards and Vertex Shaders Chapter 20 - Working Outside of Cartesian Coordinates Chapter 21 - Bezier Patches Chapter 22 - Character Animation—Matrix Palette Skinning Chapter 23 - Simple Color Manipulation Chapter 24 - Do-It-Yourself Lighting in a Vertex Shader Chapter 25 - Cartoon Shading Chapter 26 - Reflection and Refraction Chapter 27 - Shadows Part 1—Planar Shadows Chapter 28 - Shadows Part 2—Shadow Volumes Chapter 29 - Shadows Part 3—Shadow Maps Part VI - Pixel Shader Techniques Chapter 30 - Per-Pixel Lighting Chapter 31 - Per-Pixel Lighting—Bump Mapping Chapter 32 - Per-Vertex Techniques Done per Pixel Part VII - Other Useful Techniques Chapter 33 - Rendering to a Texture—Full-Screen Motion Blur Chapter 34 - 2D Rendering—Just Drop a “D” Chapter 35 - DirectShow: Using Video as a Texture Chapter 36 - Image Processing with Pixel Shaders Chapter 37 - A Much Better Way to Draw Text Chapter 38 - Perfect Timing Chapter 39 - The Stencil Buffer Chapter 40 - Picking: A Plethora of Practical Picking Procedures In Conclusion… Index List of Figures List of Tables List of Sidebars CD Content Real-Time Rendering Tricks and Techniques in DirectX Kelly Dempski © 2002 by Premier Press All rights reserved No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system without written permission from Premier Press, except for the inclusion of brief quotations in a review Premier Press, Inc is a registered trademark of Premier Press, Inc Publisher: Stacy L Hiquet Marketing Manager: Heather Buzzingham Managing Editor: Sandy Doell Acquisitions Editor: Mitzi Foster Series Editor: André LaMothe Senior Project Editor: Heather Talbot Technical Reviewer: André LaMothe Microsoft and DirectX are registered trademarks of Microsoft Corporation in the United States and/or other countries NVIDIA, the NVIDIA logo, nForce, GeForce, GeForce2, and GeForce3 are registered trademarks or trademarks of NVIDIA Corporation in the United States and/or other countries All other trademarks are the property of their respective owners Important: Premier Press cannot provide software support Please contact the appropriate software manufacturer’s technical support line or Web site for assistance Premier Press and the author have attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer Information contained in this book has been obtained by Premier Press from sources believed to be reliable However, because of the possibility of human or mechanical error by our sources, Premier Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from use of such information Readers should be particularly aware of the fact that the Internet is an ever-changing entity Some facts may have changed since this book went to press ISBN: 1-931841-27-6 Library of Congress Catalog Card Number: 2001097326 Printed in the United States of America 02 03 04 05 06 RI 10 Technical Reviewer: Andre LaMothe Copy Editor: Laura R Gabler Interior Layout: Scribe Tribe Cover Design: Mike Tanamachi CD-ROM Producer: Arlie Hartman Indexer: Sharon Shock For Rachel Acknowledgments I can’t thank my wife Rachel enough She has graciously put up with six frantic months of writing Her contributions ranged anywhere from simple emotional support to helping me debug pixel shaders in the early hours of the morning This book would not have been possible without her patience and support I’d like to thank all my friends and family for their support I’ve had less time to spend with the people who are important to me Thank you for your patience these past months Thanks to Stan Taylor, Anatole Gershman, Edy Liongosari, and everyone at Accenture Technology Labs for their support Many thanks to Scott Kurth for proofreading, suggestions, and the occasional reality check Also, many thanks to Mitu Singh for taking the time to help me with many of the images and equations I have the privilege of working with a fantastic group of people Also, I’d like to thank all the other people who worked on this book I really appreciate the help of Emi Smith, Mitzi Foster, Heather Talbot, Kris Simmons, and André LaMothe Thanks to all of you for walking me through my first book Finally, I need to thank Philip Taylor (Microsoft), Jason Mitchell (ATI), Sim Dietrich (nVidia), and many other presenters from each of these three companies Much of what I have learned comes from their excellent presentations and online materials Their direct and indirect help is greatly appreciated Also, I’d like to thank Sim Dietrich for taking the time and effort to write the foreword All the people mentioned above contributed in some way to the better aspects of this book I deeply appreciate their contributions About the Author Kelly Dempski has been a researcher at Accenture’s Technology Labs for seven years His research work has been in the areas of multimedia, Virtual Reality, Augmented Reality, and Interactive TV, with a strong focus on photo-realistic rendering and interactive techniques He has authored several papers and one of his projects is part of the Smithsonian Institution’s permanent collection on Information Technology Letter from the Series Editor Let me start by saying, buy this book! Real-Time Rendering Tricks and Techniques in DirectX is simply the most advanced DirectX book on the market—period! The material in this book will be found in no other book, and that’s all there is to it I am certain that the author Kelly Dempski is an alien from another world since there’s no way a human could know this much about advanced DirectX I know since I am from another planet This book covers all the topics you have always heard about, but never knew exactly how to implement in real time In recent times, Direct3D has become a very complex and powerful API that leverages hardware to the max The programmers at Microsoft are not playing games with it and Direct3D is in sync with the hardware that it supports, meaning if there is hardware out there that does something, you can be sure that Direct3D can take advantage of it In fact, Direct3D has support for operations that don’t exist Makes me wonder if Bill has a time machine The only downfall to all this technology and functionality is that the learning curve is many months to years—and that’s no joke Try learning Direct3D on your own, and it will take you 1–2 years to master it The days of just figuring things out are over, you need a master to teach you, and then you can advance from there Real-Time Rendering Tricks and Techniques in DirectX starts off making no assumptions about what you know The first part of the book covers mathematics, matrices, and more After that groundwork is laid, general Direct3D is covered in l, so we are all on the same page The coverage of Direct3D alone is worth the price of the book However, after the basic Direct3D coverage, the book starts into special effects programming using various advanced techniques like vertex shaders and pixel shaders This stuff is completely voodoo It’s not like it’s hard, but you simply would have no idea where to start if you were to read the DirectX SDK Kelly knows where to start, where to end, and what goes in the middle Now, I don’t want to get you too excited, but if you read this book you WILL know how to perform such operations as advanced texture blending, lighting, shadow mapping, refraction, reflection, fog, and a bazillion other cool effects such as “cartoon” shading What I like about this book is that it really does live up to its title, and the material is extremely advanced, but at the same time very easy to understand The author makes things like refraction seem so easy He’s like, “a dot product here, change the angle there, texture index, and output it, and whammo done!”—and you’re like sitting there going “wow, it works!” The point is that something like refraction or reflection seems easy theoretically, but when you try to it, knowing where to begin is the problem With Real-Time Rendering Tricks and Techniques in DirectX, you don’t have to worry about that; you will learn the best approaches to every advanced rendering technique known to humanity and be able to skip the learning and experimentation that comes with trial and error Additionally, the book has interesting tips and asides into the insides of DirectX and why something should or should not be done in a specific way; thus, no stone is left unturned Well, I can’t tell you how much I recommend this book; you will be a Direct3D master by the end of reading it And if that wasn’t enough, it even covers how to use DirectShow! I finally can play a damn video! Sincerely, André LaMothe SERIES EDITOR Foreword Over the past few years, the field of real-time graphics has come into its own Consumer-level graphics processors are now available with speed and capabilities rivaling the most expensive workstations of just a few years ago In addition, recent papers presented at Siggraph, the premier graphics research conference and exhibition, have been more and more focused on real-time graphics, as opposed to off-line rendering techniques The biggest advance in consumer real-time graphics over the past year has been the advent of programmable shading technology as found in the NVIDIA GeForce3TM and GeForce4 TM Ti line of products, in addition to the Microsoft Xbox TM GPU (Graphics Processing Unit), and the Radeon TM 8500 series from ATI Technologies Now, instead of being tied into a fixed-function lighting model that includes diffuse and specular terms evaluated per-vertex, one can program a custom lighting solution, taking into account per-pixel bump mapping, reflection, refraction, Fresnel, and self-shadowing terms This flexibility not only improves the capability of realistic traditional rendering, but opens the door to non-photorealistic techniques, such as cel shading, hatching, and the like This very flexibility does come at a cost, however, and one aspect of this cost is complexity As developers fashion their shading models to consider more and more factors, each parameter to the shading function must be provided somehow Initially, these will be supplied via artist-authored texture maps and geometric models Over time, however, as graphics processors (GPUs) become even more programmable, many parameters will be filled in procedurally via pseudo-random noise generation It will fall to the artists to merely specify a material type such as ‘marble’, ‘oak’, etc and a few parameters, and the actual pattern of the surface will be created on the fly in real time Another way the complexity of programmable shading becomes expensive is via education It’s much simpler to learn the ins and outs of a ‘configurable’ vertex or pixel engine, like that exposed by a GPU such as the original GeForce or GeForce2 Learning not only what to do, but also what is possible is a challenge to be sure In one sense, it’s trivial to implement an algorithm with a fully general CPU with true floating point capability, but it takes a real-time graphics programmer’s talent to get last year’s research paper running in real time on today’s hardware, with limited floating point capability and processing time Lastly, the blessing of flexibility comes with the curse of the new Due to the recent development of realtime programmable shading, the tools are only now beginning to catch up Major 3D authoring applications are tackling this problem now, so hopefully the next major revision of your favorite 3D authoring tool will include full support for this exciting new technology Over time, real-time graphics languages will move from the current mix of floating-point and fixed-point assembly level, to fully general floating point throughout the pipeline They will also shed the form of assembly languages, and look more like high-level languages, with loops, conditionals, and function calls, as well as professional IDEs (Integrated Development Environments) specifically tailored to realtime graphics needs Hopefully you will find Real-Time Rendering Tricks and Techniques in DirectX a good starting place to begin your journey into the future of real-time graphics D Sim Dietrich Jr February 2002 Introduction If you’re reading this book at home, good—because I have every intention of making this a book that you can use as a reference for a long time If you’re reading this at the bookstore, then bring it home (they appreciate it if you pay first) because it’s terribly inconvenient to run to the bookstore each time you need to implement one of the cool techniques this book describes When I taught a programming class, I told them, “I don’t know everything, but I know where to find everything.” Every good programmer has a couple of books that are good to refer to periodically This is one of those books, but before we get to the good stuff, let’s get some basic introductions out of the way Who Is This Book For? Simply put, this book is for you! If you’re reading this, you picked this book off the shelf because you have an interest in learning some of the more interesting parts of graphics programming This book covers advanced features in a way that is easy for beginners to grasp Beginners who start at the beginning and work their way through should have no problem learning as the techniques become more advanced Experienced users can use this book as a reference, jumping from chapter to chapter as they need to learn or brush up on certain techniques How Should You Read This Book? The goal of this book is two-fold First, I want you to be able to read this book through and gain an understanding of all the new features available in today’s graphics cards After that, I want you to be able to use this as a reference when you begin to use those features day to day It is a good idea to read the book cover to cover, at least skimming chapters to get a feel for what is possible Then later, as you have specific needs, read those chapters in depth Frequently, I answer questions from people who weren’t even aware of a technique, much less how to implement it Your initial reading will help to plant some good ideas in your head Also, many of the techniques in this book are implemented around one or two examples that highlight the technique While you’re reading this, it’s important to view each technique as a tool that can be reapplied and combined with other techniques to solve a given problem For each technique, I’ll discuss the broader possibilities, but in many cases, you might discover a use for a technique that I never imagined That’s the best thing that can happen If you’ve gotten to the point that you can easily rework and reapply the techniques to a wider range of problems, then you have a great understanding of the technology What Is Included? CD Content I explain higher-level concepts in a way that is clear to all levels of readers The text itself explains the basic techniques, as well as a step-by-step breakdown of the source code The CD contains all the source code and media needed to run the examples In addition, I’ve included some tools to help get you started in creating your own media Who Am I? I am a researcher with Accenture Technology Labs A large part of my job involves speaking to people about technology and what the future holds for businesses and consumers Some past projects have received various awards and numerous publications My most recent projects involved work in augmented and virtual reality, and many other projects involved gaming consoles and realistic graphics I’m not a game programmer, but a large part of my work involves using and understanding the same technologies I have the luxury of working with new hardware and software before it becomes readily available, and it’s my job to figure it out and develop something new and interesting Unlike many other authors of advanced books, I not have a background in pure mathematics or computer science My background is in engineering From that perspective, my focus is implementing techniques and getting things done rather than providing theoretical musings And if for some reason I don’t succeed, you know where to reach me! Kelly Dempski Graphics_book@hotmail.com Part I: First Things First Chapter List Chapter 1: 30 Graphics: A Historical Perspective Chapter 2: A Refresher Course in Vectors Chapter 3: A Refresher Course in Matrices Chapter 4: A Look at Colors and Lighting Chapter 5: A Look at the Graphics Pipeline If you’re like me, you’re dying to jump headlong into the code Slow down! These first several chapters deal with some of the basic concepts you’ll need in later chapters Advanced readers might want to skip this section entirely, although I recommend skimming through the sections just to make sure that you really know the material For beginner readers, it’s a good idea to read these chapters carefully Different people will pick up on the concepts at different rates These chapters move through the material quickly If you read a chapter once and you don’t fully understand it, don’t worry too much Later chapters continually explain and use the concepts I know for me personally, I don’t truly understand something until I use it If you’re like me, read the chapters, digest what you can, and wait until you start coding Then, return to these earlier chapters to reinforce the concepts behind the code Here’s a brief breakdown of the chapters in this section: Chapter 1, “3D Graphics: A Historical Perspective,” is a brief look back at the last couple years of technological development in the area of 3D graphics It’s not a complete retrospective, but it should give you an idea of why this is an interesting time to be in the field Chapter 2, “A Refresher Course in Vectors,” runs through the definition of a vector and the ways to mathematically manipulate vectors Because so many of the techniques are based on vector math, I highly recommend that you read this chapter Chapter 3, “A Refresher Course in Matrices,” briefly explains matrices and the associated math It explains matrices from an abstract perspective, and beginners might need to get to the later chapter on transformations before they completely understand The discontinuity is intentional I want to keep the abstract theory separate from the implementation because the theory is reused throughout many different implementations Chapter 4, “A Look at Colors and Lighting,” explains the basics of color and lighting This theory provides the basis of many shader operations in later chapters If you’ve never implemented your own lighting before, reading this chapter is a must Chapter 5, “A Look at the Graphics Pipeline,” is the final look at “the basics.” You will look at how data moves through the graphics card and where performance bottlenecks can occur This chapter provides a basis for later performance tips Chapter 1: 3D Graphics: A Historical Perspective Overview I was in school when DOOM came out, and it worked like a charm on my state-of-the-art 486/25 At the time, 3D graphics were unheard of on a consumer PC, and even super-expensive SGI machines were not extremely powerful A couple years later, when Quake was released, 3D hardware acceleration was not at all mainstream, and the initial version of Quake ran with a fast software renderer However, Quake was the “killer app” that pushed 3D hardware acceleration into people’s homes and offices In July 2001, Final Fantasy debuted as the first “hyper-realistic,” completely computer-generated feature film Less than a month later, nVidia’s booth at SIGGRAPH featured scenes from Final Fantasy running in real time on its current generation of hardware It wasn’t as high quality as the movie, but it was very impressive In a few short years, there have been considerable advances in the field How did we get here? To answer that, you have to look at the following Hardware advances on the PC Hardware advances on gaming consoles Advances in movies A brief history of DirectX A word about OpenGL Hardware Advances on the PC Prior to Quake, there was no killer app for accelerated graphics on consumer PCs Once 3D games became popular, several hardware vendors began offering 3D accelerators at consumer prices We can track the evolution of hardware by looking at the product offerings of a particular vendor over the years If you look at nVidia, you see that one of its first hardware accelerators was the TNT, which was released shortly after Quake in 1995 and was followed a year later by the TNT2 Over the years, new products and product revisions improved at an exponential rate In fact, nVidia claims that it advances at Moore’s Law cubed! It becomes difficult to accurately chart the advances because we cannot just chart processor speed The geForce represents a discontinuity as the first graphics processing unit (GPU), capable of doing transform and lighting operations that were previously done on the CPU The geForce2 added more features and faster memory, and the geForce3 had a significantly more advanced feature set In addition to increasing the processing speed of the chip, the overall work done per clock cycle has increased significantly The geForce3 was the first GPU to feature hardware-supported vertex and pixel 10 Figure 6.1: The Options dialog box for include files Figure 6.2: A very simple application Note the painting issues Figure 6.3: The lifespan of the simple application Chapter 7: Creating and Managing the Direct3D Device Figure 7.1: Application flow Chapter 8: Everything Starts with the Vertex Figure 8.1: Everything starts with vertices Figure 8.2: Vertex buffer operations Figure 8.3: Your first real application Chapter 9: Using Transformations Figure 9.1: Two instances of transformed geometry Figure 9.2: Scene from Figure 9.1 from two different viewpoints Figure 9.3: The effects of simple transformations Figure 9.4: The effects of multiple transformations Figure 9.5: Geometry offset from the origin Figure 9.6: The view frustum Figure 9.7: Scene from Figure 9.1 with two different “lenses.” Figure 9.8: A relatively complex ship model Figure 9.9: Examples of different transformations Chapter 10: From Vertices to Geometry Figure 10.1: Vertex normal on a surface Figure 10.2: Triangles in a triangle list Figure 10.3: Triangles in a triangle fan Figure 10.4: Triangles in a triangle strip Figure 10.5: Surface normals on a hard edge with and without degenerate triangles 750 Figure 10.6: Rendering geometry and a mesh Figure 10.7: The layout of the triangle fan Figure 10.8: The layout of the triangle strip Chapter 11: Fixed Function Lighting Figure 11.1: Examples of attenuation Figure 11.2: Spot light cone Figure 11.3: Falloff values and their curves Figure 11.4: Point lights on meshes Figure 11.5: Spot lights on meshes Chapter 12: Introduction to Textures Figure 12.1: Image data in memory Figure 12.2: Mip map levels Figure 12.3: Simple texture coordinates Figure 12.4: Repeating checkerboard patterns Figure 12.5: Simple textured quads in the sample app Figure 12.6: Different mip map levels Chapter 13: Texture Stage States Figure 13.1: Multitextured rectangles Figure 13.2: Different addressing modes applied to rectangles Figure 13.3: Texture magnification Figure 13.4: Texture minification Figure 13.5: Two different filtering modes Chapter 14: Depth Testing and Alpha Blending Figure 14.1: A scene and the contents of its depth buffer Figure 14.2: Creating 32-bit textures with the DirectX texture tool 751 Figure 14.3: A “front” texture, its alpha channel, and a “back” texture Figure 14.4: The testing application Figure 14.5: Close-up of alpha-tested region Chapter 15: Vertex Shaders Figure 15.1: Inputs and outputs of a vertex shader Figure 15.2: Multiple streams into a single shader Figure 15.3: Transformations based on the transposed transformation matrix Figure 15.4: A very simple shader application Chapter 16: Pixel Shaders Figure 16.1: A pixel shader’s place in the pipeline Figure 16.2: Pixel shader architecture Figure 16.3: Normal and dependent texture reads Figure 16.4: Very simple pixel shader application Figure 16.5: Pixel shader setup in a vertex shader Figure 16.6: Color and alpha channels of the texture Figure 16.7: Tile with varying directional reflection Chapter 17: Using Shaders with Meshes Figure 17.1: From the file to the screen Figure 17.2: The relationships between the buffers Figure 17.3: The sample application Figure 17.4: Cloning a mesh Figure 17.5: Remapping vertex data Chapter 18: Simple and Complex Geometric Manipulation with Vertex Shaders Figure 18.1: Objects scaled along their normals 752 Figure 18.2: Moving a vertex along a scaled normal vector Figure 18.3: Taylor series approximations Figure 18.4: Wave parameters Figure 18.5: Warping with a sine wave Chapter 19: Billboards and Vertex Shaders Figure 19.1: A 2D plane aligned with the viewer’s direction vectors Figure 19.2: Billboard street lamp glow Figure 19.3: Vertex and constant data and the resulting billboard Figure 19.4: Easy depth correction of the glow Figure 19.5: Rescaling the billboard with the shader Chapter 20: Working Outside of Cartesian Coordinates Figure 20.1: Polar coordinates Figure 20.2: Cylindrical and spherical coordinates Figure 20.3: The components of the shader Figure 20.4: The application in action Figure 20.5: Scaling only the angle Figure 20.6: Scaling only the radius Chapter 21: Bezier Patches Figure 21.1: The Bezier patch application rendered in wireframe Figure 21.2: A Bezier curve defined with four control points Figure 21.3: The basis functions Figure 21.4: Changing slopes on a curve Figure 21.5: Graphing the derivative Figure 21.6: A very simple surface normal Figure 21.7: Bezier patch solid rendering 753 Figure 21.8: Bezier patch wireframe Chapter 22: Character Animation—Matrix Palette Skinning Figure 22.1: Sample poses from a running animation Figure 22.2: Key frame animation Figure 22.3: Key frame animation with too few key frames Figure 22.4: Skinning animation Figure 22.5: Skinning in the sample application Figure 22.6: Bone influences on joint vertices Figure 22.7: Variable resolution in the skin Chapter 23: Simple Color Manipulation Figure 23.1: Shader color values and real color values Figure 23.2: The depth encoded model Figure 23.3: “X-ray” glasses Figure 23.4: The cone of the x-ray effect Figure 23.5: A view of the vertices of the outer box Chapter 24: Do-It-Yourself Lighting in a Vertex Shader Figure 24.1: Vectors in consistent coordinate systems Figure 24.2: Transformed vertices without transformed normals Figure 24.3: Transformed vertices with transformed normals Figure 24.4: World transformations from the object point of view Figure 24.5: The effects of the world and inverse world matrices Figure 24.6: Directional lighting Figure 24.7: Per-vertex point lighting Figure 24.8: Per-vertex spot lighting Chapter 25: Cartoon Shading 754 Figure 25.1: Encoding the sum of two values in a texture Figure 25.2: Encoding a complex function in a shader Figure 25.3: Realistic and toon shading Figure 25.4: Spectra for different renderings Figure 25.5: Screenshot with edging Figure 25.6: Finding edge vertices Figure 25.7: Levels of the edge texture Figure 25.8: Different shading textures Chapter 26: Reflection and Refraction Figure 26.1: A cube map texture Figure 26.2: Perfect reflection of incoming light Figure 26.3: Reflection into a cube map Figure 26.4: Reflection equation in steps Figure 26.5: The final reflection equation Figure 26.6: Refraction between water and air Figure 26.7: Refraction approximation Figure 26.8: Sample application with test cube map Figure 26.9: The effects of different blending factors Figure 26.10: The reflection/refraction application Chapter 27: Shadows Part 1—Planar Shadows Figure 27.1: Simple planar shadows Figure 27.2: The coefficients of the plane equation Figure 27.3: Three points on a plane Figure 27.4: Flattened geometry Figure 27.5: Planar shadow rendering steps 755 Figure 27.6: Planar shadows Figure 27.7: The light’s path in the “sky.” Figure 27.8: The shadow and the plane Figure 27.9: The application in action Chapter 28: Shadows Part 2—Shadow Volumes Figure 28.1: Shadow volume of a plane on a plane Figure 28.2: Partially extruded volume Figure 28.3: Extruded vertices Figure 28.4: The first “normal” pass Figure 28.5: Drawing the front faces of the shadow volume Figure 28.6: Drawing the back faces of the shadow volume Figure 28.7: Looking through the shadow volume Figure 28.8: Shadow volume rendering steps Figure 28.9: The completed scene Figure 28.10: Shadows on other objects Figure 28.11: Shadows without Z biasing Figure 28.12: Incorrect volume for low tessellation mesh Chapter 29: Shadows Part 3—Shadow Maps Figure 29.1: Distances from a light Figure 29.2: The light texture applied to the scene Figure 29.3: Low-resolution light texture Figure 29.4: Medium-resolution light texture Figure 29.5: Camera view and light view of a simple scene Figure 29.6: Light view mapped to camera view Figure 29.7: The final output with mapped shadows 756 Chapter 30: Per-Pixel Lighting Figure 30.1: Lightmapping a wall Figure 30.2: A spot light cross section Figure 30.3: Projective spot light cone Figure 30.4: Spot light in action Figure 30.5: Attenuation texture Figure 30.6: Attenuated light Figure 30.7: Texture attenuated light Figure 30.8: Attenuation gradients Figure 30.9: Attenuation texture Figure 30.10: Point lighting Figure 30.11: Projective texture issues Chapter 31: Per-Pixel Lighting—Bump Mapping Figure 31.1: Lighting with vertex normals Figure 31.2: Lighting with pixel normals Figure 31.3: Bump solid and wireframe views Figure 31.4: Height map applied to a mesh Figure 31.5: 1D normals from a 1D height map Figure 31.6: Height map and normal map Figure 31.7: Per-triangle basis vectors Figure 31.8: Bump mapped torus Figure 31.9: Bump mapped torus with a pixel shader Chapter 32: Per-Vertex Techniques Done per Pixel Figure 32.1: Per-pixel reflection Figure 32.2: Per-pixel reflection with lighting 757 Figure 32.3: Per-pixel toon shading Figure 32.4: Per-pixel toon shading with edging Figure 32.5: Changing the toon colors Chapter 33: Rendering to a Texture—Full-Screen Motion Blur Figure 33.1: Setting the viewport to match the screen size Figure 33.2: Rendering to a cube map Figure 33.3: Motion blur of a moving circle Figure 33.4: Virtual images in motion Figure 33.5: Virtual object in motion Figure 33.6: Moderate motion-blur effect Figure 33.7: Extreme blurring effect Chapter 34: 2D Rendering—Just Drop a “D” Figure 34.1: Perspective and its effect on rendered objects Figure 34.2: Scene with an orthogonal projection matrix Figure 34.3: Default 2D layout Figure 34.4: Off-center ortho projection Figure 34.5: Changing the sprite origin Figure 34.6: Application in action Figure 34.7: Performance differences Chapter 35: DirectShow: Using Video as a Texture Figure 35.1: DirectShow filter graph for an AVI file Figure 35.2: Filter graph for an MP3 file Figure 35.3: The texture filter Figure 35.4: The AVI-file-to-texture filter graph Figure 35.5: Setting the paths for the DirectShow base classes 758 Figure 35.6: The video application Chapter 36: Image Processing with Pixel Shaders Figure 36.1: A scene in black and white Figure 36.2: Brightening a scene Figure 36.3: Looking at a single color channel Figure 36.4: Inverted image Figure 36.5: Solarized image Figure 36.6: Adjusting contrast of a color value Figure 36.7: Increasing the contrast of a scene Figure 36.8: Decreasing the contrast of a scene Figure 36.9: Equal and invert color curves Figure 36.10: Color curves for simple functions Figure 36.11: Darkening lower range values Figure 36.12: Dependent reads from a color curve texture Figure 36.13: Accentuating values in a given range Figure 36.14: Playing with color values Figure 36.15: Removing a range of colors Figure 36.16: Convolution kernels for a blur filter Figure 36.17: Edge-finding kernel Figure 36.18: Simplified edge-finding kernel Figure 36.19: Results of the edge kernel Chapter 37: A Much Better Way to Draw Text Figure 37.1: Printable characters in a texture Chapter 39: The Stencil Buffer Figure 39.1: Two triangles updating a stencil buffer 759 Figure 39.2: Drawing with different stencil tests Figure 39.3: A stenciled sniper scope Figure 39.4: Drawing the stencil shape Figure 39.5: Zoomed pass with stencil Chapter 40: Picking: A Plethora of Practical Picking Procedures Figure 40.1: Simple sample GUI Figure 40.2: Rectangle test Figure 40.3: Circle test Figure 40.4: Projecting a ray into a scene Figure 40.5: Box traveling over terrain Figure 40.6: Moving the box and finding the height Figure 40.7: Box with correct height values Figure 40.8: Box with correct alignment Figure 40.9: Contents of the render target Figure 40.10: Shot with selected object List of Tables Chapter 2: A Refresher Course in Vectors Table 2.1: D3DX Vector Data Types Table 2.2: D3DX Vector Functions Chapter 3: A Refresher Course in Matrices Table 3.1: D3DX Matrix Data Types Table 3.2: D3DX Matrix Functions Chapter 4: A Look at Colors and Lighting Table 4.1: Members of the D3DLIGHT8 Structure 760 Chapter 7: Creating and Managing the Direct3D Device Table 7.1: D3DDEVTYPE Definitions Table 7.2: Device Behavior Flags Table 7.3: D3DPRESENT_PARAMETERS Structure Table 7.4: Clear Parameters Chapter 8: Everything Starts with the Vertex Table 8.1: FVF Flag Definitions Table 8.2: Vertex Buffer Usage Flags Table 8.3: D3DPOOL Values Table 8.4: Vertex Buffer Locking Flags Chapter 9: Using Transformations Table 9.1: D3DX Projection Matrix Functions Chapter 10: From Vertices to Geometry Table 10.1: D3DXLoadMeshFromX Parameters Chapter 13: Texture Stage States Table 13.1: D3DTEXTUREOP Values Table 13.2: Texture Argument Flags Table 13.3: Texture Coordinate Index Flags Table 13.4: D3DTEXTUREADDRESS Modes Table 13.5: D3DTEXTURETRANSFORMFLAGS Table 13.6: D3DTEXTUREFILTERTYPEs Chapter 14: Depth Testing and Alpha Blending Table 14.1: D3DCMPFUNC Values Chapter 15: Vertex Shaders Table 15.1: Vertex Shader Output Registers 761 Table 15.2: Vertex Shader Instructions Table 15.3: Vertex Shader Macros Table 15.4: Vertex Registers Table 15.5: Register Types Table 15.6: D3DXAssembleShader Parameters Chapter 16: Pixel Shaders Table 16.1: Pixel Shader “Setup” Instructions Table 16.2: Pixel Shader Arithmetic Instructions Table 16.3: Pixel Shader Texture Addressing Instructions Table 16.4: Pixel Shader Source Register Modifiers Table 16.5: Pixel Shader Source Register Selectors Table 16.6: Pixel Shader Instruction Modifiers Table 16.7: Pixel Shader Register Limitations Chapter 39: The Stencil Buffer Table 39.1: D3DCMPFUNC Values Table 39.2: D3DSTENCILOP Values Chapter 40: Picking: A Plethora of Practical Picking Procedures Table 40.1: Intersection Functions List of Sidebars Chapter 5: A Look at the Graphics Pipeline Higher-order Surfaces Chapter 12: Introduction to Textures What’s a Mip Map? Chapter 13: Texture Stage States 762 Gauss—Isn’t He the Magnet Guy? Chapter 15: Vertex Shaders Processing in a Shader Setting Constants Chapter 16: Pixel Shaders Pixel Shaders versus Vertex Shaders Chapter 20: Working Outside of Cartesian Coordinates Why “Cartesian”? What about Lighting and Shading? Chapter 21: Bezier Patches La Vie de Msr Bezier Derivatives of Other Functions Creating s and t Values Chapter 24: Do-It-Yourself Lighting in a Vertex Shader Reference Frames Chapter 25: Cartoon Shading Technically… Chapter 26: Reflection and Refraction Upon Reflection… Snell’s Law Chapter 30: Per-Pixel Lighting Per Pixel? What about Directional Lights? Chapter 31: Per-Pixel Lighting—Bump Mapping 763 Per-Vertex Basis Vectors Your Good Friend D3DX Chapter 32: Per-Vertex Techniques Done per Pixel Debugging Fun for the Whole Family Upon Reflection on Refraction Chapter 34: 2D Rendering—Just Drop a “D” On the Other Hand… For the Object Inclined Chapter 35: DirectShow: Using Video as a Texture All about AVI Chapter 39: The Stencil Buffer Updating Multiple Buffers 764 ... you will find Real- Time Rendering Tricks and Techniques in DirectX a good starting place to begin your journey into the future of real- time graphics D Sim Dietrich Jr February 2002 Introduction... knowing where to begin is the problem With Real- Time Rendering Tricks and Techniques in DirectX, you don’t have to worry about that; you will learn the best approaches to every advanced rendering. .. days of just figuring things out are over, you need a master to teach you, and then you can advance from there Real- Time Rendering Tricks and Techniques in DirectX starts off making no assumptions

Ngày đăng: 18/10/2019, 16:02