Game Development Reference
In-Depth Information
PS_OUTPUT Main(PS_INPUT input)
{
// zero out members of output
PS_OUTPUT output = (PS_OUTPUT)0;
// sample appropriate textures
vector b = tex2D(BaseTex, input.base);
vector s = tex2D(SpotLightTex, input.spotlight);
vector t = tex2D(StringTex,
input.text);
// combine texel colors
vectorc=b*s+t;
// increase the intensity of the pixel slightly
c += 0.1f;
// save the resulting pixel color
output.diffuse = c;
return output;
}
First the pixel shader declares three sampler objects, one for each
texture that we are blending. Next the input and output structures are
defined. Notice that we don't have any color values input into the pixel
shader; this is because we are using the textures exclusively for color-
ing and lighting; that is, BaseTex holds the color of our surface and
SpotLightTex is our light map. The pixel shader outputs a single
color value that specifies the color that we have computed for this par-
ticular pixel.
The Main function samples the three textures using the tex2D
function. That is, it fetches the texel from each texture that is to be
mapped to the pixel that we are currently computing based on the spec-
ified texture coordinates and sampler object. We then combine the
texel colors with the statement c=b*s+t . Next we brighten
the overall pixel color a bit by adding 0.1f to each component. Finally,
we save the resulting pixel color and return it.
Now that we have looked at the actual pixel shader code, we shift
gears and look at the application code. The application has the following
relevant global variables:
IDirect3DPixelShader9* MultiTexPS = 0;
ID3DXConstantTable* MultiTexCT
= 0;
IDirect3DVertexBuffer9* QuadVB = 0;
IDirect3DTexture9* BaseTex = 0;
IDirect3DTexture9* SpotLightTex = 0;
IDirect3DTexture9* StringTex
= 0;
Search WWH ::




Custom Search