Chapter 5: Shader Setup in DirectX

OVERVIEW

Dealing with network executives is like being nibbled to death by ducks.

--Eric Sevareid

This section assumes that you have had some experience with using DirectX, at least with getting a Direct3D device loaded. (A device you initialized to interface to the underlying hardware.) You should also understand the discussion in Chapter 2 on exactly what we mean by a vertex. DirectX 8 introduced the concept of a vertex element stream, so now all data is fed to the rendering engine via one or more vertex element streams. The basics of getting ready to use shaders (or the FFP rendering) is as follows:

  1. Create a D3D device.

  2. Check to make sure all features you need are supported in that device.

  3. Create your vertex data structure(s) (vertex element).

  4. Create the vertex shader interface declaration(s).

  5. Create your vertex buffer(s) and fill it with data.

  6. Create and assemble your vertex and pixel shaders.

  7. Associate a vertex stream with the vertex buffers.

  8. Select the vertex and pixel shaders into the device.

  9. Set any shader constants.

  10. Render your data.

Typically, you'll take steps 1–6 at initialization time, though if your program goes into different segments (e.g., loading different levels in a game), steps 3–6 might occur at this time. Steps 7–10 might occur in your rendering loop, possibly iterating over steps 8–10 if you have multiple passes on the same data. If you use effects files (supported by the DirectX utility library), you can store shaders as part of the .X files along with your data and get the shader selection automatically when you render. Effects files are discussed in the DirectX help files that come with the DirectX SDK. You can find information about the SDK at [MSSDK].



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net