Game Development Reference
In-Depth Information
input into the pixel shader depends on how many colors and texture
coordinates were output by the vertex shader. For example, if a vertex
shader outputs two colors and three texture coordinates, then Direct3D
will calculate two colors and three texture coordinates per pixel and
input them into the pixel shader. We map the input colors and texture
coordinates to variables in our pixel shader program using the semantic
syntax. Using the previous example, we would write:
struct PS_INPUT
{
vector c0 : COLOR0;
vector c1 : COLOR1;
float2 t0 : TEXCOORD0;
float2 t1 : TEXCOORD1;
float2 t2 : TEXCOORD2;
};
For output, a pixel shader outputs a single computed color value for the
pixel:
struct PS_OUTPUT
{
vector finalPixelColor : COLOR0;
};
18.3 Steps to Using a Pixel Shader
The following list outlines the steps necessary to create and use a pixel
shader.
1. Write and compile the pixel shader.
2. Create an IDirect3DPixelShader9 interface to represent the
pixel shader based on the compiled shader code.
3. Enable the pixel shader with the IDirect3DDevice9::Set-
PixelShader method.
Of course, we have to destroy the pixel shader when we are done with
it. The next few subsections go into these steps in more detail.
18.3.1 Writing and Compiling a Pixel Shader
We compile a pixel shader the same way that we compile a vertex
shader. First, we must write a pixel shader program. In this topic, we
write our shaders in HLSL. Once the shader code is written we com-
pile the shader using the D3DXCompileShaderFromFile function, as
described in section 16.2. Recall that this function returns a pointer to
an ID3DXBuffer that contains the compiled shader code.
Search WWH ::




Custom Search