Game Development Reference
In-Depth Information
p' = pM
The texture coordinates and color are left unmodified and will be pass down to the pixel
shader.
3.11.2 Pixel Shaders
Thepixelshaderissmallexecutableprogramthatcalculatesthecolorofapixelonarender
target. Pixel shaders receive the data it needs to compute the final color value from the
vertex shader and from user defined custom parameters that are stored in constant register
space on the graphics hardware.
Pixel shaders are used to output a calculated color that may be sent down by the vertex,
compute the color and apply lighting properties, translucency, normal mapping, shadows,
and any number of per pixel effects.
A simple pixel shader that outputs per-vertex color information may look like the follow-
ing:
struct SVertexData
{
float4 position : SV_Position;
float4 color : COLOR0;
float2 texCoord : TEXCOORD0;
};
float4 ps_vertexcolor(SVertexData input) : SV_Target0
{
return input.color;
};
The input parameter is sent by the vertex shader and contains the screen space position of
the pixel, its interpolated texture coordinate and a vertex color that was set during the cre-
ation or last update of the vertex buffer.
In order to apply a texture in a pixel shader, a texture and its respective sampler must be
provided so that it can be sampled at the interpolated texture coordinate sent by the vertex
shader.
Texture2D texture0 : register(t0);
SamplerState sampler0 : register(s0);
float4 ps_texture(SVertexData input) : SV_Target0
{
return texture0.Sample(sampler0, input.texCoord);
};
Search WWH ::




Custom Search