Game Development Reference
In-Depth Information
Note:
Since we are using pixel shaders, we will need to remember
to change the compile target to a pixel shader target (e.g.,
ps_2_0
)
instead of a vertex shader target (e.g.,
vs_2_0
). The compile targets
are specified through a parameter of the
D3DXCompileShader-
FromFile
function. See section 16.2 for details.
18.3.2
Creating a Pixel Shader
Once we have the compiled shader code, we can obtain a pointer to an
IDirect3DPixelShader9
interface, which represents a pixel shader,
using the following method:
HRESULT IDirect3DDevice9::CreatePixelShader(
CONST DWORD *pFunction,
IDirect3DPixelShader9** ppShader
);
pFunction
—Pointer to compiled shader code
ppShader
—Returns a pointer to an
IDirect3DPixelShader9
interface
For example, suppose the variable
shader
is an
ID3DXBuffer
that
contains the compiled shader code. Then to obtain an
IDirect3D-
PixelShader9
interface, we would write:
IDirect3DPixelShader9* MultiTexPS = 0;
hr = Device->CreatePixelShader(
(DWORD*)shader->GetBufferPointer(),
&MultiTexPS);
Note:
To reiterate, the
D3DXCompileShaderFromFile
is the func-
tion that would return the compiled shader code (
shader
).
18.3.3
Setting a Pixel Shader
After we have obtained a pointer to an
IDirect3DPixelShader9
interface that represents our pixel shader, we can enable it using the
following method:
HRESULT IDirect3DDevice9::SetPixelShader(
IDirect3DPixelShader9* pShader
);
The method takes a single parameter where we pass a pointer to the
pixel shader that we wish to enable. To enable the shader we created in
section 18.3.2, we would write:
Device->SetPixelShader(MultiTexPS);
Team-Fly
®
Search WWH ::
Custom Search