Rendering EngineThe rendering engine forms an important part of Direct3D. It is responsible for taking a scene definition in terms of points in 3D, the different texture specifications, the lights and the camera specifications, and rendering ready, so that it can be displayed on the display device. The functionality of the rendering engine is provided using three modules, namely the transformation module, the lighting module and the rasterization module. Each of these modules can be hardware accelerated, transparent to the user of the application. The application developer only has to put the detection facility into the application, which will allow it to query the hardware to find and use its capabilities, if present. Figure 2 shows the three modules of the rendering engine and their interactions with the Direct3D API, before displaying the results on the rendering target, which is the 2D display surface. The diagram shows the sequence of operations performed on the data, before it is displayed.
The 3D data to be displayed, is given to the transformation module, which maps the 3D data onto its equivalent 2D data. This 2D data is then given to the lighting module, which calculates the light received by the data, considering the lights in the scene. The lit data is then given to the rasterization module, which calculates the transparency and applies the texture to the data. After rasterization, the data is 2D, lit using the different lights in the scene and may also have the specified texture maps applied to them. Let us now consider each of the modules in a bit more detail. Transformation ModuleThe transformation module is the first of the three modules of the rendering engine. This module handles the geometry transformations in the rendering engine. To do this, it uses three four-by-four (4x4) matrices, namely the view transformation matrix, the world transformation matrix and the projection matrix. For an explanation of these three matrices, refer [5], [6], [11], [12], [13] and [14]. The three matrices are maintained in three state registers, namely the viewing matrix, the world matrix and the projection matrix, repectively. This module uses one more state register, the viewport, for holding the dimensions of the 2D display area. The transformation module combines all the matrices into one composite matrix and uses this for computations, as using only one matrix, as opposed to four, speeds up the calculations in the application. It is possible to set the states of the state registers separately, in addition to setting the value of the composite matrix. But, it is advisible to let Direct3D calculate the composite matrix, as the matrix multiplication operations required, have been specially optimized in Direct3D. Additionally, the newer versions of DirectX make use of MMX technology. Figure 3 shows a diagrammatic representation of the transformation module.
Lighting ModuleThe lighting module of the rendering engine is the second of the three modules. It uses the data provided by the transformation module and calculates the lighting information for the received data. This module maintains a stack of the current lights and the ambient light level and the different material properties of the data. All this information is used while calculating the light falling at a particular point in the scene. Figure 4 shows a diagrammatic representation of the lighting module.
The lighting module can be operated in any one of the two lighting models it supports. The two models supported are:
Rasterization ModuleThe rasterization module is the last of the three modules of the rendering engine. This module takes only execute calls and the data and displays it onto the display surface. On being given the execute call, the module goes through the list of vertices to be displayed and generates the transfomed vertices to be rendered. Clipping parameters can also be specified in this module. The module also culls back-facing triangles, viz. the triangles whose surface normals face away from the camera. An important point about this module is that it renders only clockwise oriented triangles. Figure 5 shows a diagrammatic representation of the rasterization module.
For more details on the Direct3D API and its features, refer [3] and [2].
|
|||||||||||