Game Development Reference
In-Depth Information
Take a closer look at the calls to
ID3D11DeviceContext::VSSetConstant
Buffers()
at the end. I purposely moved them together to make a point: When
there are more multiple constant buffers in a shader, you must use the first parame-
ter,
StartSlot
, to identify which constant buffer you are setting. Since the
cbMatrices
structure in the vertex shader is defined as being in register zero, the
slot number in
VSSetConstantBuffers()
is set to zero. For the lights, it is set to
slot one, and the materials are set to slot two. If the
register
directive weren
t used,
the slots you would specify would simply be in the order in which the constant
buffers were declared in the shader.
'
A pixel shader is responsible for painting pixels, or rasterization. Every pixel on the
screen is a combination of an object
s color, the texture color if one exists, and light-
ing. The pixel shader below is an example of one that calculates all of these values on
a per-pixel basis.
'
//
—————————————————————————————————————————————————————————————
// File: GameCode4_PS.hlsl
// The pixel shader file for GameCode4
//
—————————————————————————————————————————————————————————————
//
—————————————————————————————————————————————————————————————
// Globals
//
—————————————————————————————————————————————————————————————
cbuffer cbObjectColors : register( b0 )
{
float4 g_vDiffuseObjectColor
: packoffset( c0 );
float4 g_vAmbientObjectColor
: packoffset( c1 );
bool
g_bHasTexture: packoffset( c2.x );
};
// Textures and Samplers
//
—————————————————————————————————————————————————————————————
Texture2D g_txDiffuse : register( t0 );
SamplerState g_samLinear : register( s0 );
// Input structure
//
—————————————————————————————————————————————————————————————
struct PS_INPUT
{
float4 vDiffuse : COLOR0;
float2 vTexcoord
: TEXCOORD0;
};