| Foreword | xiii |
| Acknowledgments | xvii |
| Introduction | xix |
| PART I PROGRAMMING ASSEMBLY-LANGUAGE SHADERS | |
| 1 Vertex Shader Introduction | 3 |
| Vertex Processing | 4 |
| Vertex Shader Tutorial 1: Transforming Vertices | 6 |
| Vertex Shader Tutorial 1a: Adding a Diffuse Color | 19 |
| Summary | 23 |
| 2 Vertex Shader Virtual Machine | 25 |
| Virtual Machine Block Diagram | 25 |
| Shader Layout | 27 |
| Registers | 28 |
| Instructions | 32 |
| Setup Instructions | 33 |
| Arithmetic Instructions | 34 |
| Macro-Op Instructions | 35 |
| Texture Instructions | 36 |
| Flow-Control Instructions | 36 |
| Modifiers Extend the Virtual Machine | 37 |
| Vertex Shader Version Differences | 39 |
| Summary | 41 |
| 3 Vertex Shader Examples | 43 |
| Example 1: Vertex Shader Fog | 43 |
| Example 2: Vertex Shader SDK Sample | 47 |
| Example 3: Vertex Blend SDK Sample | 56 |
| Summary | 65 |
| 4 Pixel Shader Virtual Machine | 67 |
| Pixel Processing | 67 |
| Pixel Shader Virtual Machine Block Diagram | 72 |
| Shader Layout | 74 |
| Registers | 75 |
| Input Registers for Versions 1_1 to 1_4 | 76 |
| Output Register for Versions 1_1 to 1_4 | 77 |
| Input Registers for Version ps_2_0 and Later | 77 |
| Instructions | 80 |
| Setup Instructions | 82 |
| Arithmetic Instructions | 83 |
| Macro-Op Instructions | 84 |
| Texture Instructions | 85 |
| Flow-Control Instructions | 87 |
| Instruction Set Summary | 89 |
| Modifiers Extend the Virtual Machine | 89 |
| Modifiers for Versions 1_1 to 1_4 | 90 |
| Modifiers for ps_2_0 and Later | 92 |
| Pixel Shader Version Differences | 92 |
| Summary | 93 |
| 5 Pixel Shader Examples | 95 |
| Example 1: 2-D Image Processing | 95 |
| Example 2: Multilayered Textures | 101 |
| PART II PROGRAMMING HLSL SHADERS | |
| 6 HLSL Introduction | 109 |
| Tutorial 1: Start with a Vertex Shader: Hello World | 110 |
| Add a Diffuse Color | 113 |
| Tutorial 2: Add a Pixel Shader | 115 |
| Complementing | 118 |
| Darkening | 118 |
| Masking the Red Out | 119 |
| Displaying Red Only | 119 |
| Tutorial 3: Add a Procedural Texture | 120 |
| Building the Tutorials | 122 |
| Creating Resources | 123 |
| Rendering | 129 |
| Summary | 130 |
| 7 The Language | 131 |
| Data Types | 131 |
| Scalar Types | 131 |
| Variable Declaration | 132 |
| Type Modifiers | 132 |
| Storage Class Modifiers | 134 |
| Semantics | 135 |
| Annotations | 135 |
| Vector Types | 135 |
| Matrix Types | 138 |
| Constructors | 142 |
| Casting | 143 |
| Integer Math | 144 |
| Complex Data Types | 144 |
| Expressions and Statements | 149 |
| Statements | 155 |
| Functions | 160 |
| Function Declaration | 160 |
| Function Body | 167 |
| Intrinsic Functions | 168 |
| Summary | 169 |
| 8 HLSL Examples | 171 |
| Glow Example | 171 |
| Apply a Texture | 173 |
| Add the Glow | 183 |
| Sparkle Example | 192 |
| Vertex Shader | 195 |
| Texture Shader | 198 |
| Pixel Shader | 199 |
| Diffuse Only | 201 |
| Diffuse and Gloss | 201 |
| Diffuse, Gloss, and Sparkle | 201 |
| Vertex and Pixel Shader Creation | 202 |
| Procedural Texture Creation | 204 |
| Environment Map Creation | 205 |
| Mesh Creation | 206 |
| Render | 210 |
| HLSL Experimentation in EffectEdit | 211 |
| Summary | 212 |
| PART III PROGRAMMING EFFECTS | |
| 9 Effect Introduction | 215 |
| Effects and the 3-D Pipeline | 215 |
| An Effect with an Assembly-Language Vertex Shader | 217 |
| Effect Global Variables | 218 |
| Effect State | 219 |
| HLSL Vertex Shader | 222 |
| Characteristics of Effects | 225 |
| Save and Restore State | 225 |
| Use Multiple Techniques and Passes | 227 |
| Share Parameters | 229 |
| Use Semantics to Find Parameters | 230 |
| Use Handles to Get and Set Parameters | 230 |
| Add Parameter Information with Annotations | 231 |
| Building an Effect | 232 |
| Create an Effect | 232 |
| Validate an Effect | 234 |
| Render an Effect | 234 |
| Summary | 236 |
| 10 Assembly-Language Effect Examples | 237 |
| Example 1: Asm Vertex Shader with Lighting | 237 |
| Example 2: Asm Vertex Shader and Pixel Shader with Texturing | 243 |
| Example 3: Asm Vertex Shader Environment Map | 249 |
| 11 HLSL Effect Examples | 259 |
| Example 1: Vertex and Pixel Shader with Per-Pixel Lighting | 259 |
| Example 2: Multiple-Pass Rendering with Alpha Blending | 265 |
| EffectEdit: Interactive Effect Development | 274 |
| The Code Pane | 274 |
| The Render Pane | 275 |
| The Rendering Options Pane | 275 |
| The Compile Results Pane | 275 |
| Getting an Effect to Run in EffectEdit | 276 |
| Example 3: Hemispheric Lighting | 278 |
| PART IV APPENDIXES | |
| A Vertex Processing | 287 |
| Transformations | 287 |
| Affine Transform | 289 |
| Left-to-Right Order | 290 |
| World Transform | 291 |
| View Transform | 292 |
| Projection Transform | 294 |
| Vertex Fog | 297 |
| Lights and Materials | 299 |
| Ambient Light | 300 |
| Diffuse Light | 300 |
| Specular Light | 301 |
| Emissive Light | 302 |
| Light Attenuation | 302 |
| Spotlight Cone | 303 |
| B Asm Shader Instructions | 305 |
| Instructions | 305 |
| C HLSL Reference | 347 |
| 1: Data Types | 347 |
| 1.1 Intrinsic Types | 347 |
| 1.2 User-Defined Types | 348 |
| 1.3 Type Casts | 349 |
| 2: Operators | 351 |
| 3: User-Defined Functions | 353 |
| 3.1 Vertex Shader Semantics | 355 |
| 3.2 Pixel Shader Semantics | 356 |
| 3.3 Procedural Texture Shader Semantics | 357 |
| 4: Intrinsic Functions | 357 |
| 5: Pixel Shader 1_x Considerations | 386 |
| 5.1 ps_1_1, ps_1_2, and ps_1_3 | 387 |
| 5.2 ps_1_4 | 387 |
| 5.3 Modifiers | 388 |
| 5.4 Texture Instructions | 391 |
| 6: Keywords | 397 |
| 7: Directives | 398 |
| 8: Lexical Conventions | 398 |
| 8.1 White Space | 398 |
| 8.2 Floating-Point Numbers | 399 |
| 8.3 Integer Numbers | 399 |
| 8.4 Characters | 400 |
| 8.5 Identifiers | 401 |
| 8.6 Strings | 400 |
| 9: Grammar | 400 |
| 9.1 Program | 400 |
| 9.2 Declarations | 400 |
| 9.3 Usages | 401 |
| 9.4 Types | 401 |
| 9.5 Structures | 402 |
| 9.6 Annotations | 403 |
| 9.7 Variables | 403 |
| 9.8 Initializers | 403 |
| 9.9 Functions | 403 |
| 9.10 Techniques | 404 |
| 9.11 Statements | 405 |
| 9.12 Expressions | 405 |
| 9.13 Tokens | 407 |
| D Effect Reference | 409 |
| 1: Effect Format | 409 |
| 1.1 Variables | 409 |
| 1.2 Techniques | 411 |
| 1.3 Passes | 411 |
| 1.4 Expressions | 411 |
| 1.5 Annotations | 413 |
| 1.6 Cloning and Sharing | 414 |
| 1.7 Handles | 415 |
| 1.8 IDs and Semantics | 416 |
| 1.9 Usages | 417 |
| 1.10 Literals | 417 |
| 1.11 Validation | 418 |
| 2: Effect States | 418 |
| 2.1 Light States | 419 |
| 2.2 Material States | 420 |
| 2.3 Render States: Vertex Pipeline vs. Pixel Pipeline | 421 |
| 2.4 Sampler States | 426 |
| 2.5 Sampler Stage States | 426 |
| 2.6 Shader States | 428 |
| 2.7 Shader Constant States | 429 |
| 2.8 Texture States | 431 |
| 2.9 Texture Stage States | 431 |
| 2.10 Transform States | 433 |
| Summary | 433 |
| INDEX | 435 |