I have been developing this 3D engine for two and a half years. I have been counting more than August rows since 40 thousand, and more than July this year rows since 0.21 million. I feel a sense of accomplishment, but more is the worry: Can these codes work together well, fast enough? There must be a lot of bugs, because the test intensity is not high after all. This is not the most important thing. Will there be fatal negligence in the architecture? Will it be vulnerable to unknown demands? A few days ago, I looked at the code I wrote two years ago. I felt a lot of dissatisfaction. I began to deploy the code in an instant. For more than two years, it was indeed time to go down, it seems that there is not much time to rewrite it. There are still many things to do next, and the free and loose development environment cannot be maintained forever. there are also some worries: Do I really try my best? Does it take so long to complete these functions? Are they really valuable? I can't even remember what I did a year ago. How much time can I spend? There is a possibility that the negative side can really come up with many things in the east and west. however, to be positive, there are also a lot of good news. In the past two years, I have learned at least a lot and accumulated experience in 3D graphics, which is not as unfamiliar as I did two years ago, the script has some experience. The compiler is more proficient in writing and the appearance is more beautiful. (This is very important. Isn't writing a program just to write something nice ?), The template is also used more skillfully than before, and some of the solution to the problem is quite satisfactory. In the more than 0.2 million line of spam code, there are even some bright spots, so it is comforting.
So I plan to write something about this engine from this hot summer, so I can keep it as a souvenir, and I can sort out my ideas and make future memos, 3. I can publish some of my ideas for communication. I dare not speak of the advanced education. At least I want to persuade people to be good and teach them well (how can I speak with Guo Degang ), it would be nice if someone could see these things and get some inspiration. Let's start with the most basic article about the rendering process of the device.
The device of d3d9 is a tool provided by d3d for us to draw 3D images. Its Drawing Process is roughly like this: * First, the device user needs to prepare vertex data, that is, an array of vertex data, called *. Then, array a is passed into the rendering pipeline of the device. *. The device processes each vertex in sequence. There are two modes: Fixed pipeline and shader mode. The so-called fixed pipeline is a fixed sequence implemented inside the device, users can only control it by setting various parameters (some renderstate). Of course, this is not flexible enough, so the shader mode is available. That is to say, users need to write a program segment (called vertex shader ), send it to the device, and then the device uses this clip to process each vertex. this program fragment is executed on the video card. *. After each element of the input vertex array a is converted, it is stored in another array B. Each element in array B must contain at least one pivoting space for cropping. *. Array B is passed into the next computing phase of device. In this phase, the vertices (converted) in array B are organized into triangles, then cut the triangles (The position of the perspective space contained in the vertex data) and remove the back (note that the back is irrelevant to the normal of the vertex ), the remaining triangles are stored in an array C. (Note that in this phase, the vertex array is changed to a triangle array) *. Array C is passed into the next computing phase, rasterized. For each triangle in array C, map them from the Perspective space to the screen space first, then find out the pixels they cover on the screen (the number of pixels covered by a triangle may be large). For each pixel, based on its position in the triangle, use linear interpolation of triangle vertices to calculate a pixel data (note that pixel data is obtained by interpolation of triangle vertex data, so their data types are consistent ), the pixel data calculated from all triangles is finally stored in an array D. (In this phase, the number of triangles is changed to a pixel data array) *. Array D is passed into the next computing phase. In this phase, the device will perform some preliminary filtering on these pixels, mainly for stenric test (according Buffer value) and Z-test (compare the Z value of this pixel with the Z-buffer value ), according to the test results, some modifications will be made to the stencel buffer (using a set of render states to control the process), and the pixels of the test will be stored in the array E. *. Array e is passed into the next computing phase. In this phase, device processes each pixel data. This phase also has two modes: Fixed pipeline and shader mode, similar to the vertex processing stage, you can also write a program segment to process each pixel data, called pixel shader. pixel data may contain various types of data, but after processing at this stage, the output is very simple, generally a color value and an Alpha value (transparency ), you can also output a Z value, but it does not seem to be commonly used. in pixel shader, you can also use special commands to discard the subsequent processing of a certain pixel. after all the pixel data is processed, the result is stored in an array F. *. Array F enters the next stage. In this stage, Alpha test (based on the Alpha value of the pixel) is performed, and Alpha test is the last test, the pixels of Alpha test can be used to ensure that the pixels are drawn to the screen. the pixels of test will update their Z values to the Z-buffer (controlled by a group of render states ), the pixels of test are stored in the array G. *. Array g enters the next stage. In this phase, the pixels in array G are mixed with the existing pixels on the screen. There are various ways to mix these pixels, controlled by a series of render states. after mixing, pixels are "painted" to the screen. Basically, the process is like this. There are many links, and there are also many skills in each link. There are too many things to pay attention to. I don't think this process is very important, although it is not difficult to understand, it is not so easy to remember it very skillfully and use all the links to solve practical problems. so I did not bother writing it again, so I hope I can further deepen my impression.
I am writing code about multi-threaded rendering recently. The next write may be related.
Thank you for correcting one of my mistakes in the comments downstairs. stencel test and depth test are indeed only performed after pixel shader. Although this seems unreasonable, however, standard rendering should be like this, but it seems that some graphics cards will do some early test (early-Z and early-stencer) before pixelshader to improve performance, I hope the more video cards, the better. it seems that I want to re-check the performance improvement of the engine by using stencel buffer, but it seems that the tests at that time did improve some performance.
Address: http://www.cnblogs.com/ixnehc/archive/2008/09/02/1282350.html