Game Development Reference
In-Depth Information
Texture Tex;
sampler S0 = sampler_state
{
Texture = (Tex);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};
Here we have associated the texture
Tex
with the texture stage that
S0
corresponds with and also set the sampler states for the sampler
stage that
S0
corresponds with. We have set all this directly and cleanly
in the effect file!
19.2.3
Vertex and Pixel Shader Objects
The
vertexshader
and
pixelshader
HLSL intrinsic types repre-
sent vertex and pixel shaders, respectively. They are used in the effects
framework to refer to the particular vertex and/or pixel shader that is
to be used for a particular rendering pass. A
vertexshader
and/or
pixelshader
type can be set from the application through the
ID3DXEffect
interface with the
ID3DXEffect::SetVertex-
Shader
and
ID3DXEffect::SetPixelShader
methods, respec-
tively. For example, let
Effect
be a valid
ID3DXEffect
object, let
VS
be a valid
IDirect3DVertexShader9
object, and let
VSHandle
be a
D3DXHANDLE
that refers to a
vertexshader
object in the effect file;
then we can initialize the vertex shader that
VSHandle
refers to by
writing:
Effect->SetVertexShader(VSHandle, VS);
We look at
SetVertexShader
and
SetPixelShader
more when we
examine how to set variables in the effect file from the application.
Alternatively, we can write the vertex and/or pixel shader directly
into the effect file. Then using a special compiling syntax, we can set a
shader variable. The following example illustrates how to initialize a
pixelshader
variable
ps
.
// Define Main:
OUTPUT Main(INPUT input){...}
// Compile Main:
pixelshader ps = compile ps_2_0 Main();
Observe that after the
compile
keyword we specify the version name,
followed by the shader's entry point function. Note that when using this
style to initialize a vertex/pixel shader object, the entry point function
must be defined in the effect file.
Search WWH ::
Custom Search