我歸納一下就是:準備頂點和圖元數據----》傳到D3D渲染管線----》處理頂點數據(固定、shader)----》幾何處理(裁剪、背面剔除、光柵化)----》像素處理(紋理采樣)----》著色
牢記這個:
Direct3D Graphics Pipeline
The graphics pipeline provides the horsepower to efficiently process and render Direct3D scenes to a display, taking advantage of available hardware. This figure conceptually illustrates the building blocks of the pipeline:
\Documentation\DirectX9\directx_sdk.chm::/BlockDiag_Graphics.gif)
Pipeline Component |
Description |
Related Topics |
Vertex Data |
Untransformed model vertices are stored in vertex memory buffers. |
Vertex Buffers (Direct3D 9), IDirect3DVertexBuffer9 |
Primitive Data |
Geometric primitives, including points, lines, triangles, and polygons, are referenced in the vertex data with index buffers. |
Index Buffers (Direct3D 9), IDirect3DIndexBuffer9, Primitives, Higher-Order Primitives (Direct3D 9) |
Tessellation |
The tesselator unit converts higher-order primitives, displacement maps, and mesh patches to vertex locations and stores those locations in vertex buffers. |
Tessellation (Direct3D 9) |
Vertex Processing |
Direct3D transformations are applied to vertices stored in the vertex buffer. |
Vertex Pipeline (Direct3D 9) |
Geometry Processing |
Clipping, back face culling, attribute evaluation, and rasterization are applied to the transformed vertices. |
Pixel Pipeline (Direct3D 9) |
Textured Surface |
Texture coordinates for Direct3D surfaces are supplied to Direct3D through the IDirect3DTexture9 interface. |
Direct3D Textures (Direct3D 9), IDirect3DTexture9 |
Texture Sampler |
Texture level-of-detail filtering is applied to input texture values. |
Direct3D Textures (Direct3D 9) |
Pixel Processing |
Pixel shader operations use geometry data to modify input vertex and texture data, yielding output pixel color values. |
Pixel Pipeline (Direct3D 9) |
Pixel Rendering |
Final rendering processes modify pixel color values with alpha, depth, or stencil testing, or by applying alpha blending or fog. All resulting pixel values are presented to the output display. |
Pixel Pipeline (Direct3D 9) |
Direct3D System Integration
This figure shows the relationships between a Window application, Direct3D,GDI, and the hardware:
\Documentation\DirectX9\directx_sdk.chm::/d3dsysint.gif)
Direct3D exposes a device-independent interface to an application. Direct3D applications can exist alongsideGDI applications, and both have access to the computer's graphics hardware through the device driver for the graphics card. UnlikeGDI, Direct3D can take advantage of hardware features by creating a hal device.
A hal device provides hardware acceleration to graphics pipeline functions, based upon the feature set supported by the graphics card. Direct3D methods are provided to retrieve device display capabilities at run time. (See IDirect3D9::GetDeviceCaps and IDirect3DDevice9::GetDeviceCaps.) If a capability is not provided by the hardware, the hal does not report it as a hardware capability.
For more information about hal and reference devices supported by Direct3D, see Device Types (Direct3D 9).
*.首先Device的使用者要準備好頂點數據,也就是一個頂點的數組,稱為A
*.然后這個數組A被傳入device的渲染管線
*.device內部依次對每個頂點進行處理,有兩種模式,固定管線和shader模式,所謂固定管線就是device內部實現的一個固定的程 序,用戶只能通過設定各種參數(一些RenderState)來控制它,當然這不夠靈活,所以有了shader模式,也就是說,用戶需要寫一個程序片段 (所謂vertex shader),傳給device,然后device使用這個片段對每個頂點進行處理.這個程序片段是在顯卡上執行的.
*.傳入的頂點數組A的每一個元素被轉換后,存儲到另一個數組B中.數組B中的每個元素必須至少包含一個透視空間的位置,用來做裁剪.
*.數組B被傳入到device的下一個計算階段,在這個階段里,數組B中的(被轉換過的)頂點被組織成一個個三角形,然后對這些三角形進行裁 剪(利用頂點數據里包含的那一個透視空間的位置),背面剔除(注意背面剔除和頂點的法線是沒關系的),最后剩下的三角形被保存到一個數組C中.(注意在這 個階段里頂點數組變成了三角形數組)
*.數組C被傳入到下一個計算階段,光柵化,對于數組C中每一個三角形,首先把它們從透視空間映射到屏幕空間,然后找出它們在屏幕上覆蓋的像素 (一個三角形覆蓋的像素的數量有可能是很多的),對于每一個像素,根據它在三角形中的位置,通過三角形的頂點進行線性插值,計算出一個像素數據(注意像素 數據是通過三角形的頂點數據插值而來,所以它們的數據類型是一致的),所有三角形算出來的像素數據最后被存儲到一個數組D中.(在這個階段里,三角形的數 組變成了像素數據數組)
*.數組D被傳入到下一個計算階段,在這個階段里,device會對這些像素做一些初步的過濾,主要是進行stencil test(根據stencil
buffer上的值)和z-test(根據這個像素的Z值和z-buffer上的值進行比較),根據測試結果會對stencil buffer進行一些修改(使用一組render state來控制這個過程),通過這些test的像素被存儲到數組E.
*.數組E被傳入到下一個計算階段,在這個階段里,device對每個像素數據進行處理,這個階段也有兩種模式,固定管線和shader模式, 與頂點處理階段類似,用戶也可以寫一個程序片段,來對每一個像素數據進行處理,稱為pixel shader.像素數據可能包含各種類型的數據,但經過這一階段的處理后,輸出是很簡單的,一般就是一個顏色值和一個alpha值(透明度),也可以輸出 一個Z值,不過好像不常用.在pixel shader里還可以使用專門的指令來放棄某一個像素的后續處理.所有的像素數據被處理后,結果存在一個數組F中.
*.數組F進入下一個階段,在這一個階段里,進行alpha test(根據像素的alpha 值),alpha test是最后一個test了,通過了alpha test的像素可以保證繪制到屏幕上去,通過test的像素會把它們的z值更新到z-buffer中去(具體由一組render state控制),通過test的像素被存入數組G
*.數組G進入下一個階段,在這個階段里,主要是把數組G里的像素和屏幕上已有的像素進行混合,具體混合的方式有多種多樣,由一系列render state進行控制.混合以后的像素就被"畫"到屏幕上了