Direct3d: drawing pipeline

Source: Internet
Author: User

Rendering pipeline: a series of operations that must be performed from 3d to 2D.

 

Local Coordinate System-> world coordinate system-> observing coordinate system-> hiding on the back-> illumination-> cropping-> projection-> viewport coordinate system-> Rasterization

 

1. Local Space)

A local space or modeling space is a coordinate system used to create a list of triangle units of an object. The advantage of using a local coordinate system is that it can simplify the modeling process.

 

Personal Understanding: The local coordinate system is modeled on the object itself. If you want to model a teapot, the origin of the local coordinate system can be the center of the teapot. If you want to model a sphere, the origin of the local coordinate system can be the center of the ball.

 

2. World Space)

Organize all objects created on the local coordinate system to form the world coordinate system. The local coordinate system is transformed to the world coordinate system, which is called world transform ).

 

Direct3d is transformed using the idirect3ddevice9: settransform method.

 

3. Observe the Coordinate System

To simplify the operation, we transform the camera to the origin of the world coordinate system and rotate it so that the camera's optical axis is consistent with the Z axis of the world coordinate system. (Personal understanding: This is equivalent to looking at the Z axis from the coordinate origin of a person.) This transformation is called view space transformation. The transformed body is located in the view space coordinate system).

 

Direct3d is calculated by the d3dxmatrixlookatlh function.

 

4. Hide the back

Each polygon has two sides, one of which is marked as the front side and the other as the back side ). Generally, the back of a polygon is invisible because most objects in the scenario are closed objects. The front-facing polygon is called the front-facing polygon. The polygon that deviates from the camera from the front is called the back-facing polygon.

 

The Front Orientation polygon blocks the back orientation polygon behind it. Direct3d uses this to remove the polygon facing the back, which is called the back hiding.

 

In order to remove the back, direct3d needs to distinguish which polygon are facing positively and which polygon are facing on the back. By default, direct3d considers that the triangle units whose vertices are arranged clockwise (in the observed coordinate system) are positively oriented, And the vertices are arranged counterclockwise (in the observed coordinate system).

 

If, for some reason, the default Blanking Method cannot meet the application requirements, we can modify the rendering State d3drs_cullmode to achieve this goal.

 

5. Illumination

The light source is defined in the world coordinate system, but must be converted to the observed coordinate system after the scene. In the observed coordinate system, the light source illuminates the objects in the scene to achieve more realistic display.

 

6. Crop

Remove a ry other than the horizon body. This process is called clipping ). Personal Understanding: similar to the eyes of people looking at external things, some objects can be completely seen (displays in front of me), some objects are completely invisible (the door behind me ), some objects can be seen in part (I can only see the bed on the right ).

 

7. Projection

In the observed coordinate system, our task is to obtain the 2D representation of 3D scenes. The process of transforming from n dimension to n-1 dimension is called projection. There are many ways to implement projection. We are only interested in one of them, namely, perspective projection ). Perspective Projection produces the visual effect of foreshortenning.

 

Direct3d uses d3dxmatrixperspectivefovlh to create a projection matrix.

 

8. View-view Transformation

The view port transform task is to convert the vertex coordinates from the projection window to a rectangular area on the screen, which is called the view port ). In my personal understanding, the view is just a form on the desktop.

 

Direct3d: The view is represented by the d3dviewport9 structure.

 

9. Grating

After the vertex coordinates are changed to screen coordinates, we have a list of 2D triangle units. The Rasterization task is to plot each triangle unit and calculate the color value of each pixel that forms the triangle unit.

 

The grating process requires a large amount of computing. We should use the acceleration function of a dedicated graphics card. The final result of grating is a 2D image on the real screen.


 

/*************************************** ****************/

** In this article, the author is inspired by his own discretion. For more information, see the blog link. Thank you!

** I'm a beginner at direct3d. If an error exists in this article, I 'd like to acknowledge it. Thank you very much!

** Reference books: DirectX 9.0 3D Game Development Programming Basics

** Time: 2011.11.15

/*************************************** ****************/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.