1. HLSL entry
1.1What is a shader?
DirectX uses the pipeline technology (pipeline) for graphic rendering. Its architecture is as follows:
Figure 1.1 direct3d graphics pipeline
The steps for using pipelines are as follows:
1. Set data information such as vertices, elements, and textures;
2. Set MPs queue status information;
2. Rendering status
Use the setrenderstate method to set the rendering state;
In addition, use the following methods to set the conversion, material, and illumination:
Settransform
Setmaterial
Setlight
Lightenable
2. sampling device status
The setsamplerstate method is used to set the samplerstate;
2. texture layer status
Use settexturestagestate to set the texture layer status;
3. Rendering;
This is done by the d3d pipeline according to the previous settings. This operation is pre-fixed by d3d. Therefore, this pipeline technology is called fixed function pipeline );
The fixed function pipeline provides some flexibility for programming, but there are still many effects that are hard to be achieved in this way, such:
1. during rendering, we require that the vertices with Y coordinate values greater than 10 be drawn to the coordinates (0, 0, 0). In the previous fixed function pipeline, the position where the vertex is drawn is set in step 1, which cannot be changed during rendering, so it is not feasible;
2. Map the vertex to Vertex a on Texture 1 and map to vertex B on Texture 2. We require that the color of the vertex be jointly determined by A and B, that is:
Fixed Point color = a point color value * 0.7 + B point color value * 0.3
This is also not feasible in fixed pipeline programming.
The above two problems can be solved by the programmable pipeline (pragrammable pipeline.
The programmable pipeline allows you to customize a program that can be executed on the GPU, instead of the vertex processing and pixel processing phases in the fixed pipeline technology (see Figure 1.1 ), so that we can achieve greater flexibility in programming. The part that replaces vertex processing is called vertex shader, and the part that replaces pixel proccessing is called pixel shader. This is what we call the shader.