Desarrolle juegos 3d con directx
el curso esta en ingles
mi correo: jm3k2006@yahoo.es
el curso cuesta 20 soles
contenidos
conocimientos . . . . . . . . . . . . . . . . . . . . . . . . . xv
Introducción . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Partee I
pre-requisitos matematicos . . . . . . . . . . . . . . 1
Vectores en 3-espacio . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Vector igual . . . . . . . . . . . . . . . . . . . . . . . . . 5
Computando las magnitudes de los vectores. . . . . . . . . . . . . 6
Normalizando un Vector. . . . . . . . . . . . . . . . . . . . . . 7
Vector suma . . . . . . . . . . . . . . . . . . . . . . . . . 7
Vector resta . . . . . . . . . . . . . . . . . . . . . . . 8
Multiplicación escalar . . . . . . . . . . . . . . . . . . . . . . 9
Producto de puntos . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Cruce d productos . . . . . . . . . . . . . . . . . . . . . . . . 10
Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
igualdad, multiplicación escalar, y suma. . . . . . . . . 12
Multiplicación . . . . . . . . . . . . . . . . . . . . . . . . . 13
La identidad matriz. . . . . . . . . . . . . . . . . . . . . . 14
Inversas . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
La transposición de una matriz . . . . . . . . . . . . . . . . . . 15
D3DX Matrices . . . . . . . . . . . . . . . . . . . . . . . . 16
Transformaciones básicas . . . . . . . . . . . . . . . . . . . . . . . 18
La traslación matriz . . . . . . . . . . . . . . . . . . . . 20
La rotación de matrices . . . . . . . . . . . . . . . . . . . . 21
La matriz escalar . . . . . . . . . . . . . . . . . . . . . . 22
Combinando transformaciones . . . . . . . . . . . . . . . . . 23
AlgunosFunctions to Transform Vectors. . . . . . . . . . . . 25
Planes (Opcional). . . . . . . . . . . . . . . . . . . . . . . . . . 25
D3DXPLANE . . . . . . . . . . . . . . . . . . . . . . . . . 26
Punto y relación plana espacial . . . . . . . . . . . . . . . 27
Construcción . . . . . . . . . . . . . . . . . . . . . . . . . 27
Normalizando un plano. . . . . . . . . . . . . . . . . . . . . . 28
Transformando un plano . . . . . . . . . . . . . . . . . . . . . 29
Nearest Point on a Plane to a Parteicular Point. . . . . . . . 29
Rayos(opcional). . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Rayos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Intersección Rayo/Plano . . . . . . . . . . . . . . . . . . . . 31
Sumario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
v
Parte II
Direct3D Fundamentales. . . . . . . . . . . . . . . . 33
Capitulo 1
Direct3D Inicialización . . . . . . . . . . . . . . . . 35
1.1
Direct3D vista preliminar . . . . . . . . . . . . . . . . . . . . . . 35
1.1.1
los dispositivos REF . . . . . . . . . . . . . . . . . . . . 36
1.1.2
D3DDEVTYPE . . . . . . . . . . . . . . . . . . . . . 37
1.2
COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.3
Algunas Preliminares . . . . . . . . . . . . . . . . . . . . . . 37
1.3.1
superficie . . . . . . . . . . . . . . . . . . . . . . . . . 38
1.3.2
multimuestreo. . . . . . . . . . . . . . . . . . . . . . 39
1.3.3
Pixel Formatos . . . . . . . . . . . . . . . . . . . . . . 40
1.3.4 reserva de memoria
. . . . . . . . . . . . . . . . . . . . . . 41
1.3.5
The Swap Chain and Page Flipping . . . . . . . . . . 42
1.3.6
profunfos Buffers . . . . . . . . . . . . . . . . . . . . . . 43
1.3.7
Procesamiento Vertex. . . . . . . . . . . . . . . . . . . . 44
1.3.8 dispositivos capacidades
. . . . . . . . . . . . . . . . . . . 44
1.4
Inicializando Direct3D . . . . . . . . . . . . . . . . . . . . . . 45
1.4.1
adquiriendo una interfaces IDirect3D9. . . . . . . . . . . 46
1.4.2
chequeando por el Hardware procesamiento Vertex. . . . . . 47
1.4.3
Filling Out the D3DPRESENT_PARAMETERS
Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
1.4.4
Creating the IDirect3DDevice9 Interface . . . . . . . 50
1.5
Sample Application: Initializing Direct3D. . . . . . . . . . . 51
1.5.1
d3dUtility.h/cpp . . . . . . . . . . . . . . . . . . . . . 52
1.5.2
Sample Framework . . . . . . . . . . . . . . . . . . . 54
1.5.3
Sample: D3D Init . . . . . . . . . . . . . . . . . . . . 54
1.6
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Capitulo 2
The Rendering Pipeline. . . . . . . . . . . . . . . . 59
2.1
Model Representation . . . . . . . . . . . . . . . . . . . . . 60
2.1.1
Vertex Formats . . . . . . . . . . . . . . . . . . . . . 61
2.1.2
Triangles. . . . . . . . . . . . . . . . . . . . . . . . . 62
2.1.3
Indices. . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.2
The Virtual Camera . . . . . . . . . . . . . . . . . . . . . . 63
2.3
The Rendering Pipeline . . . . . . . . . . . . . . . . . . . . 64
2.3.1
Local Space . . . . . . . . . . . . . . . . . . . . . . . 65
2.3.2
World Space . . . . . . . . . . . . . . . . . . . . . . . 65
2.3.3
View Space . . . . . . . . . . . . . . . . . . . . . . . 66
2.3.4
Backface Culling . . . . . . . . . . . . . . . . . . . . 68
2.3.5
Lighting . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.3.6
Clipping . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.3.7
Projection . . . . . . . . . . . . . . . . . . . . . . . . 70
2.3.8
Viewport Transform . . . . . . . . . . . . . . . . . . 72
2.3.9
Rasterization . . . . . . . . . . . . . . . . . . . . . . 73
2.4
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
vi
Contents
Capitulo 3
Drawing in Direct3D . . . . . . . . . . . . . . . . . 75
3.1
Vertex/Index Buffers. . . . . . . . . . . . . . . . . . . . . . 75
3.1.1
Creating a Vertex and Index Buffer . . . . . . . . . . 76
3.1.2
Accessing a Buffer’s Memory . . . . . . . . . . . . . 78
3.1.3
Retrieving Information about a Vertex and
Index Buffer. . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.2
Render States . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.3
Drawing Preparations . . . . . . . . . . . . . . . . . . . . . 81
3.4
Drawing with Vertex/Index Buffers . . . . . . . . . . . . . . 82
3.4.1
IDirect3DDevice9::DrawPrimitive. . . . . . . . . . . 82
3.4.2
IDirect3DDevice9::DrawIndexedPrimitive . . . . . . 82
3.4.3
Begin/End Scene . . . . . . . . . . . . . . . . . . . . 84
3.5
D3DX Geometric Objects . . . . . . . . . . . . . . . . . . . 84
3.6
Sample Applications: Triangle, Cube, Teapot,
D3DXCreate* . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.7
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Capitulo 4
Color . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1
Color Representation . . . . . . . . . . . . . . . . . . . . . 91
4.2
Vertex Colors. . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.3
Shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.4
Sample Application: Colored Triangle . . . . . . . . . . . . . 95
4.5
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Capitulo 5
Lighting. . . . . . . . . . . . . . . . . . . . . . . . 98
5.1
Light Components . . . . . . . . . . . . . . . . . . . . . . . 98
5.2
Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.3
Vertex Normals . . . . . . . . . . . . . . . . . . . . . . . . 101
5.4
Light Sources . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.5
Sample Application: Lighting. . . . . . . . . . . . . . . . . 107
5.6
Additional Samples . . . . . . . . . . . . . . . . . . . . . . 109
5.7
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Capitulo 6
Texturing. . . . . . . . . . . . . . . . . . . . . . . 111
6.1
Texture Coordinates . . . . . . . . . . . . . . . . . . . . . 112
6.2
Creating and Enabling a Texture . . . . . . . . . . . . . . . 113
6.3
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6.4
Mipmaps. . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.4.1
Mipmap Filter . . . . . . . . . . . . . . . . . . . . . 116
6.4.2
Using Mipmaps with Direct3D . . . . . . . . . . . . 116
6.5
Address Modes . . . . . . . . . . . . . . . . . . . . . . . . 116
6.6
Sample Application: Textured Quad . . . . . . . . . . . . . 118
6.7
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Contents
vii
Capitulo 7
Blending. . . . . . . . . . . . . . . . . . . . . . . 121
7.1
The Blending Equation . . . . . . . . . . . . . . . . . . . . 121
7.2
Blend Factors . . . . . . . . . . . . . . . . . . . . . . . . . 123
7.3
Transparency . . . . . . . . . . . . . . . . . . . . . . . . . 124
7.3.1
Alpha Channels . . . . . . . . . . . . . . . . . . . . 125
7.3.2
Specifying the Source of Alpha . . . . . . . . . . . . 125
7.4
Creating an Alpha Channel Using the DirectX
Texture Tool. . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.5
Sample Application: Transparency . . . . . . . . . . . . . . 127
7.6
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Capitulo 8
Stenciling . . . . . . . . . . . . . . . . . . . . . . 131
8.1
Using the Stencil Buffer . . . . . . . . . . . . . . . . . . . 132
8.1.1
Requesting a Stencil Buffer . . . . . . . . . . . . . . 133
8.1.2
The Stencil Test . . . . . . . . . . . . . . . . . . . . 133
8.1.3
Controlling the Stencil Test . . . . . . . . . . . . . . 134
8.1.3.1
Stencil Reference Value . . . . . . . . . . . 134
8.1.3.2
Stencil Mask . . . . . . . . . . . . . . . . . 134
8.1.3.3
Stencil Value . . . . . . . . . . . . . . . . . 135
8.1.3.4
Comparison Operation . . . . . . . . . . . . 135
8.1.3
Updating the Stencil Buffer . . . . . . . . . . . . . . 135
8.1.4
Stencil Write Mask . . . . . . . . . . . . . . . . . . 137
8.2
Sample Application: Mirrors . . . . . . . . . . . . . . . . . 137
8.2.1
The Mathematics of Reflection . . . . . . . . . . . . 137
8.2.2
Mirror Implementation Overview . . . . . . . . . . 139
8.2.3
Code and Explanation . . . . . . . . . . . . . . . . . 140
8.2.3.1
Parte I . . . . . . . . . . . . . . . . . . . . . 141
8.2.3.2
Parte II . . . . . . . . . . . . . . . . . . . . . 141
8.2.3.3
Parte III . . . . . . . . . . . . . . . . . . . . 142
8.2.3.4
Parte IV . . . . . . . . . . . . . . . . . . . . 143
8.2.3.5
ParteV. . . . . . . . . . . . . . . . . . . . . 143
8.3
Sample Application: Planar Shadows. . . . . . . . . . . . . 144
8.3.1
Parallel Light Shadows . . . . . . . . . . . . . . . . 145
8.3.2
Point Light Shadows. . . . . . . . . . . . . . . . . . 146
8.3.3
The Shadow Matrix . . . . . . . . . . . . . . . . . . 146
8.3.4
Using the Stencil Buffer to Prevent Double
Blending . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8.3.5
Code and Explanation . . . . . . . . . . . . . . . . . 148
8.4
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Parte III
Applied Direct3D . . . . . . . . . . . . . . . . . . 151
Capitulo 9
Fonts. . . . . . . . . . . . . . . . . . . . . . . . . 153
9.1
ID3DXFont . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.1.1
Creating an ID3DXFont . . . . . . . . . . . . . . . . 153
viii
Contents
9.1.2
Drawing Text . . . . . . . . . . . . . . . . . . . . . 154
9.1.3
Computing the Frames Rendered Per Second . . . . 155
9.2
CD3DFont. . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.2.1
Constructing a CD3DFont. . . . . . . . . . . . . . . 156
9.2.2
Drawing Text . . . . . . . . . . . . . . . . . . . . . 156
9.2.3
Cleanup . . . . . . . . . . . . . . . . . . . . . . . . 157
9.3
D3DXCreateText . . . . . . . . . . . . . . . . . . . . . . . 157
9.4
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Capitulo 10
Meshes Parte I . . . . . . . . . . . . . . . . . . . . 160
10.1
Geometry Info . . . . . . . . . . . . . . . . . . . . . . . . 160
10.2
Subsets and the Attribute Buffer . . . . . . . . . . . . . . 161
10.3
Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10.4
Optimizing . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10.5
The Attribute Table . . . . . . . . . . . . . . . . . . . . . 165
10.6
Adjacency Info . . . . . . . . . . . . . . . . . . . . . . . . 167
10.7
Cloning. . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
10.8
Creating a Mesh (D3DXCreateMeshFVF) . . . . . . . . . 170
10.9
Sample Application: Creating and Rendering a Mesh . . . 171
10.10
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Capitulo 11
Meshes Parte II . . . . . . . . . . . . . . . . . . . . 178
11.1
ID3DXBuffer. . . . . . . . . . . . . . . . . . . . . . . . . 178
11.2
XFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.2.1
Loading an XFile . . . . . . . . . . . . . . . . . . . 180
11.2.2
XFile Materials . . . . . . . . . . . . . . . . . . . . 181
11.2.3
Sample Application: XFile . . . . . . . . . . . . . . 181
11.2.4
Generating Vertex Normals . . . . . . . . . . . . . 184
11.3
Progressive Meshes. . . . . . . . . . . . . . . . . . . . . 185
11.3.1
Generating a Progressive Mesh . . . . . . . . . . . 186
11.3.2
Vertex Attribute Weights . . . . . . . . . . . . . . 187
11.3.3
ID3DXPMesh Methods . . . . . . . . . . . . . . . 188
11.3.4
Sample Application: Progressive Mesh . . . . . . . 190
11.4
Bounding Volumes. . . . . . . . . . . . . . . . . . . . . . 193
11.4.1
AlgunosNew Special Constants . . . . . . . . . . . . 194
11.4.2
Bounding Volume Types . . . . . . . . . . . . . . . 195
11.4.3
Sample Application: Bounding Volumes. . . . . . . 196
11.5
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Capitulo 12
Building a Flexible Camera Class . . . . . . . . . . 199
12.1
Camera Design . . . . . . . . . . . . . . . . . . . . . . . 199
12.2
Implementation Details . . . . . . . . . . . . . . . . . . . 201
12.2.1
Computing the View Matrix . . . . . . . . . . . . . 201
12.2.1.1
Parte 1: Translation . . . . . . . . . . . . . 202
12.2.1.2
Parte 2: Rotation . . . . . . . . . . . . . . . 203
Contents
ix
12.2.1.3
Combining Both Partes . . . . . . . . . . . 204
12.2.2
Rotation about an Arbitrary Axis . . . . . . . . . . 205
12.2.3
Pitch, Yaw, and Roll. . . . . . . . . . . . . . . . . . 205
12.2.4
Walking, Strafing, and Flying . . . . . . . . . . . . 207
12.3
Sample Application: Camera . . . . . . . . . . . . . . . . 209
12.4
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Capitulo 13
Basic Terrain Rendering. . . . . . . . . . . . . . . 212
13.1
Heightmaps . . . . . . . . . . . . . . . . . . . . . . . . . 213
13.1.1
Creating a Heightmap . . . . . . . . . . . . . . . . 214
13.1.2
Loading a RAW File . . . . . . . . . . . . . . . . . 215
13.1.3
Accessing and Modifying the Heightmap . . . . . . 215
13.2
Generating the Terrain Geometry . . . . . . . . . . . . . 216
13.2.1
Computing the Vertices . . . . . . . . . . . . . . . 217
13.2.2
Computing the Indices—Defining the Triangles . . 220
13.3
Texturing. . . . . . . . . . . . . . . . . . . . . . . . . . . 221
13.3.1
A Procedural Approach. . . . . . . . . . . . . . . . 222
13.4
Lighting . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
13.4.1
Overview . . . . . . . . . . . . . . . . . . . . . . . 224
13.4.2
Computing the Shade of a Quad . . . . . . . . . . . 225
13.4.3
Shading the Terrain . . . . . . . . . . . . . . . . . 227
13.5
"Walking" on the Terrain . . . . . . . . . . . . . . . . . . 228
13.6
Sample Application: Terrain. . . . . . . . . . . . . . . . . 231
13.7
AlgunosImprovements . . . . . . . . . . . . . . . . . . . . 233
13.8
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Capitulo 14
Parteicle Systems . . . . . . . . . . . . . . . . . . . 235
14.1
Parteicles and Point Sprites . . . . . . . . . . . . . . . . . 235
14.1.1
Structure Format. . . . . . . . . . . . . . . . . . . 236
14.1.2
Point Sprite Render States. . . . . . . . . . . . . . 236
14.1.3
Parteicles and Their Attributes . . . . . . . . . . . . 238
14.2
Parteicle System Components . . . . . . . . . . . . . . . . 239
14.2.1
Drawing a Parteicle System. . . . . . . . . . . . . . 244
14.2.2
Randomness . . . . . . . . . . . . . . . . . . . . . 248
14.3
Concrete Parteicle Systems: Snow, Firework,
Parteicle Gun. . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
14.3.1
Sample Application: Snow . . . . . . . . . . . . . . 250
14.3.2
Sample Application: Firework . . . . . . . . . . . . 252
14.3.3
Sample Application: Parteicle Gun . . . . . . . . . . 254
14.4
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Capitulo 15
Picking. . . . . . . . . . . . . . . . . . . . . . . . 257
15.1
Screen to Projection Window Transform . . . . . . . . . . 259
15.2
Computing the Picking Ray . . . . . . . . . . . . . . . . . 260
15.3
Transforming Rays . . . . . . . . . . . . . . . . . . . . . 261
x
Contents
TEAMFLY
Team-Fly
®
15.4
Ray-Object Intersections . . . . . . . . . . . . . . . . . . 262
15.5
Picking Sample . . . . . . . . . . . . . . . . . . . . . . . 264
15.6
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Parte IV
Shaders and Effects . . . . . . . . . . . . . . . . . 267
Capitulo 16
Introduction to the High-Level Shading
Language . . . . . . . . . . . . . . . . . . . . . . 269
16.1
Writing an HLSL Shader . . . . . . . . . . . . . . . . . . 270
16.1.1
Globals . . . . . . . . . . . . . . . . . . . . . . . . 272
16.1.2
Input and Output Structures. . . . . . . . . . . . . 272
16.1.3
Entry Point Function. . . . . . . . . . . . . . . . . 273
16.2
Compiling an HLSL Shader . . . . . . . . . . . . . . . . . 275
16.2.1
The Constant Table . . . . . . . . . . . . . . . . . 275
16.2.1.1
Getting a Handle to a Constant. . . . . . . 275
16.2.1.2
Setting Constants. . . . . . . . . . . . . . 275
16.2.1.3
Setting the Constant Default Values . . . . 278
16.2.2
Compiling an HLSL Shader . . . . . . . . . . . . . 278
16.3
Variable Types . . . . . . . . . . . . . . . . . . . . . . . . 280
16.3.1
Scalar Types . . . . . . . . . . . . . . . . . . . . . 280
16.3.2
Vector Types . . . . . . . . . . . . . . . . . . . . . 281
16.3.3
Matrix Types . . . . . . . . . . . . . . . . . . . . . 282
16.3.4
Arrays. . . . . . . . . . . . . . . . . . . . . . . . . 283
16.3.5
Structures . . . . . . . . . . . . . . . . . . . . . . 283
16.3.6
The typedef Keyword . . . . . . . . . . . . . . . . 284
16.3.7
Variable Prefixes . . . . . . . . . . . . . . . . . . . 284
16.4
Keywords, Statements, and Casting . . . . . . . . . . . . 285
16.4.1
Keywords . . . . . . . . . . . . . . . . . . . . . . . 285
16.4.2
Basic Program Flow . . . . . . . . . . . . . . . . . 285
16.4.3
Casting . . . . . . . . . . . . . . . . . . . . . . . . 286
16.5
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 287
16.6
User-Defined Functions. . . . . . . . . . . . . . . . . . . 288
16.7
Built-in Functions . . . . . . . . . . . . . . . . . . . . . . 290
16.8
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Capitulo 17
Introduction to Vertex Shaders . . . . . . . . . . . 293
17.1
Vertex Declarations . . . . . . . . . . . . . . . . . . . . . 294
17.1.1
Describing a Vertex Declaration. . . . . . . . . . . 295
17.1.2
Creating a Vertex Declaration . . . . . . . . . . . . 297
17.1.3
Enabling a Vertex Declaration . . . . . . . . . . . . 297
17.2
Vertex Data Usages . . . . . . . . . . . . . . . . . . . . . 298
17.3
Steps to Using a Vertex Shader. . . . . . . . . . . . . . . 300
17.3.1
Writing and Compiling a Vertex Shader . . . . . . . 300
17.3.2
Creating a Vertex Shader . . . . . . . . . . . . . . 300
17.3.3
Setting a Vertex Shader . . . . . . . . . . . . . . . 301
Contents
xi
17.3.4
Destroying a Vertex Shader . . . . . . . . . . . . . 301
17.4
Sample Application: Diffuse Lighting. . . . . . . . . . . . 301
17.5
Sample Application: Cartoon Rendering . . . . . . . . . . 307
17.5.1
Cartoon Shading . . . . . . . . . . . . . . . . . . . 308
17.5.2
The Cartoon Shading Vertex Shader Code . . . . . 309
17.5.3
Silhouette Outlining . . . . . . . . . . . . . . . . . 311
17.5.3.1
Edge Representation . . . . . . . . . . . . 312
17.5.3.2
Testing for a Silhouette Edge. . . . . . . . 313
17.5.3.3
Edge Generation . . . . . . . . . . . . . . 314
17.5.4
The Silhouette Outlining Vertex Shader Code . . . 315
17.6
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Capitulo 18
Introduction to Pixel Shaders . . . . . . . . . . . . 318
18.1
Multitexturing Overview . . . . . . . . . . . . . . . . . . 319
18.1.1
Enabling Multiple Textures . . . . . . . . . . . . . 320
18.1.2
Multiple Texture Coordinates . . . . . . . . . . . . 321
18.2
Pixel Shader Inputs and Outputs . . . . . . . . . . . . . . 322
18.3
Steps to Using a Pixel Shader. . . . . . . . . . . . . . . . 323
18.3.1
Writing and Compiling a Pixel Shader. . . . . . . . 323
18.3.2
Creating a Pixel Shader . . . . . . . . . . . . . . . 324
18.3.3
Setting a Pixel Shader . . . . . . . . . . . . . . . . 324
18.3.4
Destroying a Pixel Shader . . . . . . . . . . . . . . 325
18.4
HLSL Sampler Objects . . . . . . . . . . . . . . . . . . . 325
18.5
Sample Application: Multitexturing in a Pixel Shader . . . 326
18.6
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Capitulo 19
The Effects Framework . . . . . . . . . . . . . . . 335
19.1
Techniques and Passes . . . . . . . . . . . . . . . . . . . 336
19.2
More HLSL Intrinsic Objects . . . . . . . . . . . . . . . . 337
19.2.1
Texture Objects . . . . . . . . . . . . . . . . . . . 337
19.2.2
Sampler Objects and Sampler States . . . . . . . . 337
19.2.3
Vertex and Pixel Shader Objects . . . . . . . . . . 338
19.2.4
Strings . . . . . . . . . . . . . . . . . . . . . . . . 339
19.2.5
Annotations. . . . . . . . . . . . . . . . . . . . . . 339
19.3
Device States in an Effect File . . . . . . . . . . . . . . . 340
19.4
Creating an Effect . . . . . . . . . . . . . . . . . . . . . . 341
19.5
Setting Constants . . . . . . . . . . . . . . . . . . . . . . 342
19.6
Using an Effect . . . . . . . . . . . . . . . . . . . . . . . 344
19.6.1
Obtaining a Handle to an Effect . . . . . . . . . . . 345
19.6.2
Activating an Effect . . . . . . . . . . . . . . . . . 345
19.6.3
Beginning an Effect . . . . . . . . . . . . . . . . . 345
19.6.4
Setting the Current Rendering Pass. . . . . . . . . 346
19.6.5
Ending an Effect . . . . . . . . . . . . . . . . . . . 346
19.6.6
Example . . . . . . . . . . . . . . . . . . . . . . . 346
xii
Contents
19.7
Sample Application: Lighting and Texturing in
an Effect File . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
19.8
Sample Application: Fog Effect . . . . . . . . . . . . . . . 352
19.9
Sample Application: Cartoon Effect. . . . . . . . . . . . . 355
19.10
EffectEdit. . . . . . . . . . . . . . . . . . . . . . . . . . 356
19.11
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Appendix
An Introduction to Windows Programming . . . . . 359
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Events, the Message Queue, Messages, and the
Message Loop . . . . . . . . . . . . . . . . . . . . . . . . 360
GUI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Hello World Windows Application . . . . . . . . . . . . . . . . 363
Explaining Hello World . . . . . . . . . . . . . . . . . . . . . . 366
Includes, Global Variables, and Prototypes. . . . . . . . . 366
WinMain . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
WNDCLASS and Registration . . . . . . . . . . . . . . . 368
Creating and Displaying the Window . . . . . . . . . . . . 370
The Message Loop . . . . . . . . . . . . . . . . . . . . . 372
The Window Procedure . . . . . . . . . . . . . . . . . . . 373
The MessageBox Function . . . . . . . . . . . . . . . . . 375
A Better Message Loop . . . . . . . . . . . . . . . . . . . . . 375
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Contents
xiii