ShaderX2: Introductions and Tutorials with DirectX 9.0

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

ShaderX2 is broken in to two volumes, with this volume intended as an introduction to shader related topics to prepare the reader for the other volume, or for other shader books. It fills that role fairly well, though it does have a few shortcomings that keep it from being a great book. The book starts off with an extensive, well-written introduction to HLSL that most beginners to the language will find quite helpful. This is followed by a handy introduction to Shader Model 3.0, which explains the changes that have been made since 2.0, and the practical applications of these changes and additions. The next several chapters are devoted to implementing "foundational" techniques using shaders. The first covers several lighting and shading techniques, providing sample shader implementations in HLSL and assembly. Most of the shaders come in multiple versions for the various shader models, which is useful for supporting these techniques on a wide range of platforms, as well as in understanding the capability differences between each model. The next chapter covers five different fog effects using HLSL shaders. Then there are two chapters on shadows, one on shadow mapping and the other on shadow volumes. The latter weighs in at over 80 pages, providing in-depth coverage of the theory behind the technique. Next up is a tutorial for using the shader development environment RenderMonkey. The usefulness of this chapter is marred by the fact that the current version of RenderMonkey has undergone some interface changes such that the text is now out of synch with the tool, making it a bit more difficult to follow along. Still, if you can work through this, the chapter will help you quickly get up and running with RenderMonkey. The last chapter of the book is about creating shader-friendly models. This chapter seems out of place since it's written more for artists than programmers (who are clearly the audience for the rest of the book), and the chapter is too brief and vague to be of much value. If you're new to shaders and HLSL, you'll likely find this book useful, though it's a little expensive for a small book (I imagine the color plates contribute to this). If the shadow and fog chapters had been moved to the other ShaderX2 book, and the final chapter had been dropped, I think that they could have reduced the price considerably and made the book more focused, turning it into a great value. As it is, though, it's still a good book that many people will benefit from.

Author(s): Wolfgang F. Engel
Publisher: Wordware Publishing, Inc.
Year: 2003

Language: English
Commentary: +OCR
Pages: 393

Team DDU......Page 1
Articles......Page 6
Contents......Page 8
Preface......Page 14
About the Authors......Page 18
Introduction......Page 22
Introduction ......Page 24
A Simple Example ......Page 25
Assembly Language and Compile Targets ......Page 27
Compilation Failure ......Page 29
The Command-line Compiler - fxc ......Page 30
Keywords ......Page 31
Data Types ......Page 32
Type Modifiers ......Page 35
Storage Class Modifiers ......Page 36
Working with Vectors ......Page 37
Type Casting ......Page 38
Samplers ......Page 40
Intrinsics ......Page 42
Math Intrinsics ......Page 43
Texture Sampling Intrinsics ......Page 46
Uniform Input ......Page 48
Varying Input ......Page 50
Shader Outputs ......Page 52
An Example Shader ......Page 54
Optimization ......Page 62
Matrix Data Type Usage ......Page 63
Integer Data Type Usage ......Page 64
Flow Control and Performance ......Page 65
Importance of Input Type Declarations ......Page 67
Precision Issues (logp, expp, lit) ......Page 68
Using the ps_1_x Compile Targets ......Page 69
Integration into an Engine Using D3DX Effects ......Page 74
Effect Files ......Page 75
The Effect API ......Page 80
Integration into an Engine without Using D3DX Effects ......Page 81
The Constant Table ......Page 82
Acknowledgments ......Page 84
Introduction ......Page 86
Flexible Input and Output Declarations ......Page 87
Predication ......Page 88
Static and Dynamic Flow Control ......Page 89
Arbitrary Swizzle ......Page 92
Destination Write Masks on Texture Instructions ......Page 93
Registers ......Page 94
Texture Sampling ......Page 96
Vertex Stream Frequency ......Page 99
Registers ......Page 101
Instructions ......Page 103
References ......Page 105
Introduction ......Page 106
Phong's Lighting Equation ......Page 107
Vertex and Pixel Shaders 2.0 ......Page 108
Vertex and Pixel Shaders 3.0 ......Page 120
Per-pixel Environment Bump Mapping with Fresnel Term ......Page 131
Mathematical Background ......Page 132
Vertex Shader ......Page 135
Pixel Shader 1.4 ......Page 138
Pixel Shader 2.0 ......Page 140
HLSL Version ......Page 142
Spherical Coordinates ......Page 145
Roughness of a Surface ......Page 146
Masking and Shadowing ......Page 147
The Oren-Nayar Model ......Page 148
Shaders ......Page 150
HLSL Version ......Page 154
Cook-Torrance Model ......Page 157
Shaders 2.0 ......Page 159
Shaders 1.4 ......Page 163
HLSL Version ......Page 166
Quality Comparison ......Page 170
Conclusion ......Page 171
References ......Page 172
Introduction ......Page 174
The Theory behind Fog Calculations ......Page 175
Fog Equation ......Page 177
Implementation ......Page 178
Technique Two: Exponential Fog ......Page 180
Fog Equation ......Page 181
Implementation ......Page 182
Technique Three: Exponential Squared Fog ......Page 185
Fog Equation ......Page 186
Implementation ......Page 187
Technique Four: Layered Fog ......Page 189
Theory and Equations ......Page 190
Implementation ......Page 191
Technique Five: Animated Fog ......Page 197
Theory and Equations ......Page 198
Implementation ......Page 199
Conclusion ......Page 201
References ......Page 202
Introduction ......Page 204
Shadow Algorithm ......Page 205
Depth Bias Problem ......Page 206
Shadow Map Filtering ......Page 208
Shaders for Shadow Map Creation ......Page 210
Shaders for Final Rendering ......Page 211
Conclusion ......Page 217
References ......Page 218
Introduction ......Page 220
Shadow Volume Concept ......Page 222
Depth-pass (z-pass) ......Page 224
Depth-fail (z-fail) ......Page 228
Finite Shadow Cover ......Page 232
Ghost Shadow ......Page 233
View Frustum Clipping ......Page 235
How It Is Done ......Page 243
Silhouette Determination ......Page 244
Forming the Shadow Volume ......Page 248
Shadow Volume Capping ......Page 254
Depth-pass Stenciling Operations (DepthPassCPU) ......Page 256
Depth-fail Stenciling Operations (DepthFailCPU) ......Page 261
Rendering Shadow Volume Capping ......Page 264
Implementation on GPU (Shaders) ......Page 266
How It Is Done ......Page 267
Preprocessing of Data ......Page 268
Forming Shadow Volume in Shaders ......Page 272
Vertex Shader Implementation (FiniteGPU) ......Page 273
Vertex Shader Implementation (InfiniteGPU) ......Page 279
Better with Shaders? ......Page 283
DirectX 9 HLSL Samples ......Page 285
Use Less for More ......Page 290
Cheat Whenever You Can ......Page 292
Fighting the Invisible ......Page 293
Scene Management Inside and Out ......Page 294
The End ......Page 298
References ......Page 299
Introduction ......Page 302
Overview of the IDE ......Page 304
Creation of Basic Illumination Effect ......Page 305
Run-Time Database Overview ......Page 306
Workspace View ......Page 308
Variable Creation and Management ......Page 309
Predefined RenderMonkey Variables ......Page 311
Stream Mapping Module ......Page 313
Model Management ......Page 316
Managing Effects ......Page 317
Pixel and Vertex Shaders ......Page 318
Editing Shaders ......Page 319
Vertex Shader Setup and Editing ......Page 321
Shader Assembly or Compilation Errors ......Page 325
Editing Assembly ......Page 326
Pixel Shader Setup and Editing ......Page 329
Preview Window ......Page 331
Editing Variables ......Page 333
Render State Block Management ......Page 337
Texturing in RenderMonkey ......Page 340
Texture Objects ......Page 341
Using Textures with HLSL Shaders ......Page 345
Render Passes ......Page 347
Renderable Texture Support ......Page 348
Editing a Renderable Texture ......Page 354
Artist Editor ......Page 355
Editing Variables in the Artist Editor Module ......Page 357
Summary ......Page 360
Tips for Creating Shader-Friendly 3D Models......Page 362
Generating Suitable Texture Coordinates ......Page 363
The Influence of "Vertex Weight" ......Page 364
Problems with Non-Convex Surfaces ......Page 366
Conclusion ......Page 368
Index......Page 378