In this chapter, What do we learn about?
First, let's look at our vs shader code:
Clolor.
...
Pixelinputtype colorvertexshader (vertexinputtype input)
{
Pixelinputtype output;
// Change the position vector to be 4 units for proper matrix calculations.
Input. position. W = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
Output. Position = MUL (input. Position, worldmatrix );
Output. Position = MUL (output. Position, viewmatrix );
Output. Position = MUL (output. Position, projectionmatrix );
// Store the input color for the pixel shader to use.
Output. Color = input. color;
Return output;
}
The information we now know is: matrixbuffer is put in the const buffer of video memory by UMD, and is passed into the shader when vs starts execution.
The shader block is usually called Cu or SIMD. It consists of many stream cores. Generally, stream core is a one-dimensional vector that can be executed (X, Y, Z, W) the unit of floating point computation. A Cu is composed of many streamcores. We have provided many diagrams in the opencl tutorial.
In vs, many stream cores are executed in parallel. Each stream core processes a vertex's vs shader computing.
From our vs shader code, we can know that it mainly performs space conversion.
// Change the position vector to be 4 units for proper matrix calculations.
Input. position. W = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
Output. Position = MUL (input. Position, worldmatrix );
Output. Position = MUL (output. Position, viewmatrix );
Output. Position = MUL (output. Position, projectionmatrix );
Converts a vertex from the world coordinate system to the same clip space. For details about the derivation, You can query the relevant information.
Mathematics. for.3d. Game. Programming. And. Computer. Graphics. lengyel.3ed. course2012 is recommended.
Note: The clip cropping space is a cube,
-R <= x <= R (r indicates the high ratio of window width)
-1 <= Y <= 1
F <= z <= N (F, N near plane and far plane distance ).
In addition, vs shader also uploads the vertex color to the next stage. In our previous tutorial, we assign the color value to the vertex directly. The general practice is to calculate the color based on the vertex direction and illumination, these codes are also in vs shader. In other subsequent tutorials, we will gradually learn this knowledge.
The vertex calculated by vs shader is placed in a FIFO. In the d3d11 logic pipeline, the next stage is Rs. In most hardware, vs FIFO (GS and tessellation operations are not considered) the content will be transmitted to a fixed pipeline called Pa (Body assembly). In this phase, perform operations such as perspective division and clip. In the next section, we will learn about the PA function.