Game Development Reference
In-Depth Information
18.3.4 Destroying a Pixel Shader
As with all Direct3D interfaces, to clean them up we must call their
Release method when we are finished with them. Continuing to use
the pixel shader we created in section 18.3.2, we have:
d3d::Release<IDirect3DPixelShader9*>(MultiTexPS);
18.4 HLSL Sampler Objects
Textures are sampled in a pixel shader using the special tex* -related
intrinsic functions of HLSL.
Note: Sampling refers to indexing a texel for a pixel based on tex-
ture coordinates for the pixel and the sampler states (texture filter
states).
See section 16.7 for details on these functions. In general, these func-
tions require us to specify two things:
The (u, v) texture coordinates used to index into the texture
The particular texture we want to index into
The (u, v) texture coordinates are, of course, given as input into the
pixel shader. The particular texture that we want to index into is identi-
fied in the pixel shader by a special HLSL object called a sampler. We
can think of a sampler object as an object that identifies a texture and
sampler stage. For example, suppose that we were using three texture
stages, which implies we need to be able to refer to each of these
stages in the pixel shader. In the pixel shader, we would write:
sampler FirstTex;
sampler SecondTex;
sampler ThirdTex;
Direct3D will associate each of these sampler objects with a unique
texture stage. Then in the application we find out the stage that a sam-
pler object corresponds with and set the appropriate texture and
sampler states for that stage. The following code illustrates how the
application would set the texture and sampler states for FirstTex :
// Create texture:
IDirect3DTexture9* Tex;
D3DXCreateTextureFromFile(Device, "tex.bmp", &Tex);
.
.
.
// Get handle to constant:
FirstTexHandle = MultiTexCT->GetConstantByName(0, "FirstTex");
Search WWH ::




Custom Search