The entire rendering process should be divided into two large parts: 1) Material Synthesis, including texture and surface properties. 2) Illumination (light), including various illumination models and rendering models. The content mainly involved here is Illumination. In OpenGL, if you need to calculate the Light Model, you need to add two properties to the vertex when specifying the vertex (Vertex): 1) The color of the vertex; 2) The normal vector of the vertex; these two The value of the property is directly involved in the calculation formula of the illumination model. Belcking to the way to calculate the normal vector: first calculate the normal vector of any triangular plane. This surface can be calculated from the three vertices in the triangular plane: a _ | _ | _ | _ c --- b
The three vertices of the triangles on the above are arranged in a clockwise, and the corresponding is the left hand coordinate system. The left-hand coordinate system used in OpenGL, and the Direct 3D is the right hand coordinate system. The calculation formula for calculating the triangular pattern according to the three vertices is: normal = cross ((ba), (ca)) in a single triangular plane, the method of the three vertices is the method of this plane, but in many cases A vertex of the geometry is shared by multiple planes, how is the normal vector of the vertex? In general, we are obtained by calculating the average of all the triangular planes of all triangles of this point. The calculation formula is: Normal = Cross ((BA), (CA)); // Note that the result is not normalized n = (N1 N2 ... NK) / || (N1 N2 ... NK) ||; this processing method is based on such an practical: two vector of the triangular area formed by the two vectors is proportional to the area of the triangle. It can be seen that the larger the area of the triangle is, the vertex method The larger the effect of the vector is also equivalent to the weighted average of the triangular method according to their area. The final rendering result of a geometric object is a result of a variety of factors, including: 1) Vertex color; 2) Texture mapping; 3) Light model (Illumination Model) The interaction between vertex colors and texture maps, or the interaction between texture maps determines the true color of the object. The real color of the object and the interaction of the light model determines the final rendering result. The illumination model can be divided into the following models: 1) Ambient Light; 2) Diffuse Reflection; 3) Specular Reflection; Specific Calculation Formula can be found in the reference. Some common rendering models below: 1) First, the simplest Shading Model is constant shading. In this model, we applied light calculation formulas once in each triangular plane, rendering the entire triangle plane with the calculation results. In OpenGL, the current rendering model can be specified by the function Glenable (GL_FLAT) is constant shading.2) Then Gouraud Shading, which belongs to the interpolation rendering. In this model, a light calculation formula is applied at the three vertices in the triangular plane, and the calculated results are called Vertex INTENSISIs. Then use Vertex INTENSIS to render the entire triangle plane along the boundary and scanning lines. In OpenGL, you can specify the current rendering model through the function glenable (GL_SMOOTH) is gouraud shading. 3) Then it is more complex pHONG shading. In this model, three vertices on the triangular plane are first interpolated on the entire plane. Each pixel point on this plane has a method that belongs to its own method, then applied light calculations on each pixel point. The formula, the calculated value is used to render the triangular plane. There is a blin shading similar to phong shading, and the differences between them are only different on the formula of the mirror reflected light, and the efficiency of the BLIN model is higher than the efficiency of the Phong model. This rendering model OpenGL is not directly supported, and the hardware support of the PRE-PIEL Shading graphics card is required. Bump mapping Bump maping is a texture map technology, but it is tightly combined with the illumination model and rendering model.