Introduction To 3D Game Programming With Directx 9.0C: A Shader Approach (Wordware Game and Graphics Library)
Format: PDF / Kindle (mobi) / ePub
Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach presents an introduction to programming interactive computer graphics, with an emphasis on game development, using real-time shaders with DirectX 9.0. The book is divided into three parts that explain basic mathematical and 3D concepts, show how to describe 3D worlds and implement fundamental 3D rendering techniques, and demonstrate the application of Direct3D to create a variety of special effects. With this book understand basic mathematical tools used in video game creation such as vectors, matrices, and transformations; discover how to describe and draw interactive 3D scenes using Direct3D and the D3DX library; learn how to implement lighting, texture mapping, alpha blending, and stenciling using shaders and the high-level shading language (HLSL); explore a variety of techniques for creating special effects, including vertex blending, character animation, terrain rendering, multi-texturing, particle systems, reflections, shadows, and normal mapping;f ind out how to work with meshes, load and render .X files, program terrain/camera collision detection, and implement 3D object picking; review key ideas, gain programming experience, and explore new topics with the end-of-chapter exercises.
3.0f); float magnitude = D3DXVec3Length( &v ); // = sqrt(14) Normalizing a Vector Normalizing a vector makes a vector’s magnitude equal to one, which is called a unit vector. We can normalize a vector by dividing each component by the vector’s magnitude, as shown here: ˆ= u u æ ux =ç , u çè u uy u uz u , ö ÷÷ ø We denote a unit vector by putting a hat over it: û. Example: Normalize the vectors u = (1, 2, 3) and v = (1, 1). Solution: From equations (2) and (3) we have u = 14 and v = 2, so:
by changing the D3DRS_CULLMODE render state. Device->SetRenderState(D3DRS_CULLMODE, Value); where Value can be one of the following: n D3DCULL_NONE—Disables back face culling entirely n D3DCULL_CW—Triangles with a clockwise wind are culled. n D3DCULL_CCW—Triangles with a counterclockwise wind are culled. This is the default state. 2.3.5 Lighting Light sources are defined in world space but transformed into view space by the view space transformation. In view space these light sources are
275 . . 275 . . 275 . . 278 . . 278 . . 280 . . 280 . . 281 . . 282 . . 283 . . 283 . . 284 . . 284 . . 285 . . 285 . . 285 . . 286 . . 287 . . 288 . . 290 . . 292 Chapter 17 Introduction to Vertex Shaders . . . . . . . . . . . 293 17.1 Vertex Declarations . . . . . . . . . . . . . . . 17.1.1 Describing a Vertex Declaration . . . . . 17.1.2 Creating a Vertex Declaration . . . . . . 17.1.3 Enabling a Vertex Declaration . . . . . . 17.2 Vertex Data Usages . . . . . . . . . . . . . . . 17.3 Steps
for point lights. Range—The maximum range that the light can travel before it “dies.” This value cannot be greater than FLT _ MAX and has no effect on directional lights. Falloff—This value is used only for spotlights. It defines how the light’s intensity weakens from the inner cone to the outer cone. This value is generally set to 1.0f. Attenuation0, Attenuation1, Attenuation2—The attenuation variables are used to define how the intensity of light weakens over distance. These variables are only
that we create later. We also define the number of subsets that the mesh will have—three. In this example, each subset is rendered with a different texture; the array Textures contains a texture for each subset, such that the ith index in the texture array is associated with the ith subset of the mesh. Finally, the variable OutFile is used to output the contents of the mesh to a text file. We pass this object to the dump* functions. The majority of the work for this sample takes place in the