First, introduce the most basic rendering model: Forward rendering (Forward Rendering). There are two basic elements of rendering: objects and lights. Forward rendering refers to the application of each light to each object in turn. The process is as follows:
For each object
for each light
to be rendered according to the illumination model
From this we can see that the time complexity of this algorithm is O (m∗n) O (m*n). If there are more objects and lights, performance does have an impact. To solve this problem, a delay rendering (Deferred shading) was invented.
The principle of this method is to postpone the illumination calculation, thereby avoiding rendering the same pixel multiple times. The process is as follows:
For each object to
store various geometry information in the G-buffer
for each light to
read from the G-buffer, rendering according to the illumination model
According to the process, the complexity of this algorithm is O (m+n) O (m+n). This greatly reduces the time complexity and reduces the waste of rendering. The key to this algorithm is what information is stored in G-buffer (geometry buffer).
According to the formula obtained in the previous article, the information related to the object includes: Object position, normal vector, texture coordinates, reflection coefficient (ka ka, kd kd, ks ks, Ke Ke), high light Index. The information you need is really quite a lot, so if you want to play the power of delayed rendering, the graphics card needs to support MRT at least, that is, the ability to render multiple pieces of information to multiple textures at the same time. Of course now the graphics card basically has this function, this aspect need not worry.
It can be seen from here that deferred rendering is actually a space-time strategy that uses the space occupied by G-buffer in exchange for rendering efficiency. Therefore, the bottleneck of delay rendering is mainly on the G-buffer, the G-buffer size is the focus of optimization. The specific optimization method is not the focus of this article, no longer repeat here.
Deferred rendering has two limitations. One is the inability to use the anti-aliasing provided by the hardware, because the geometric information of the object is basically discarded, preserving only the basic rendering information needed for each pixel. Delay rendering generally uses edge AA and other methods to anti-aliasing, the relevant information may be written after a special article to explain. Another limitation is the inability to mix translucent. Because only the pixel closest to the camera is kept on the g-buffer, it is not possible to mix correctly after the illumination is calculated, so it is generally used to render the translucent object in a forward rendering after rendering the non-semi-permeable object.