Graphics Reference
In-Depth Information
matrix to each vertex of the input model. Since this operation is carried out once on each
vertex, the vertex shader is the natural choice for performing these calculations. We also
mentioned that the model will have a texture map applied to it. Textures are typically ap-
plied in the pixel shader, so that every visible fragment can perform a texture lookup. This
results in a high graphical fidelity, which is precisely what we want.
With the general pipeline layout decided, we can now review the overall pipeline
configuration. Figure 8.7 shows the pipeline as it will be used to render a model with this
technique.
Since this is the first implementation design, we will discuss each state shown in
the pipeline above. The diagram shows the portions of the rendering pipeline that we will
use for rendering our static meshes. Beginning at the top, we have the input data to the
whole algorithm—the vertex and index buffers. These are bound to the input assembler
stage, which assembles complete vertices for consumption in the vertex shader stage. The
data layout for each vertex is displayed, for easy visualization. In addition to binding the
input buffers, we also need to configure the primitive topology and bind the current input
layout object, which is created for this specific vertex buffer layout and vertex shader
combination.
We transform the vertices from object space to clip space in the vertex shader, so it
consumes the vertices constructed by the input assembler. The vertex shader is relatively
basic, and is shown in Listing 8.1. It simply transforms the input object space position to
the clip space, and then passes the result to its output. In addition, it transforms the object
space vertex position and normal vector into world space, and subsequently calculates the
world space vector from the vertex to the light position in the scene. These world space
vectors will be used for some simple lighting calculations in the pixel shader. Finally, the
input texture coordinates are directly copied to the output structure for use in the pixel
shader. The transformation matrices are supplied to the vertex shader in a constant buffer,
shown as a connection on the right side of Figure 8.7. In addition, the lighting properties
are provided in a separate constant buffer. Once the vertex shader has executed, it emits a
single transformed vertex.
cbuffer StaticMeshTransforms
{
matrix WorldMatrix;
matrix WorldViewProjMatrix;
};
cbuffer LightParameters
{
float3 LightPositionWS;
float4 LightColor;
};
 
Search WWH ::




Custom Search