Game Development Reference
In-Depth Information
17.3 Steps to Using a Vertex Shader
The following list outlines the steps necessary to create and use a ver-
tex shader.
1. Write and compile the vertex shader.
2. Create an IDirect3DVertexShader9 interface to represent the
vertex shader based on the compiled shader code.
3. Enable the vertex shader with the IDirect3DDevice9::
SetVertexShader method.
Of course, we have to destroy the vertex shader when we are done
with it. The next subsections go into these steps in more detail.
17.3.1 Writing and Compiling a Vertex Shader
First, we must write a vertex shader program. In this topic we write
our shaders in HLSL. Once the shader code is written, we compile the
shader using the D3DXCompileShaderFromFile function, as
described in section 16.2.2. Recall that this function returns a pointer to
an ID3DXBuffer that contains the compiled shader code.
17.3.2 Creating a Vertex Shader
Once we have the compiled shader code, we can obtain a pointer to an
IDirect3DVertexShader9 interface, which represents a vertex
shader, using the following method:
HRESULT IDirect3DDevice9::CreateVertexShader(
const DWORD *pFunction,
IDirect3DVertexShader9** ppShader
);
pFunction —Pointer to compiled shader code
ppShader —Returns a pointer to an IDirect3DVertexShader9
interface
For example, suppose the variable shader is an ID3DXBuffer that
contains the compiled shader code. Then to obtain an IDirect3DVer-
texShader9 interface, we would write:
IDirect3DVertexShader9* ToonShader = 0;
hr = Device->CreateVertexShader(
(DWORD*)shader->GetBufferPointer(),
&ToonShader);
Search WWH ::




Custom Search