复习一下D3D渲染流程

复习一下D3D渲染流程

       
摘自 http://www.cnblogs.com/ixnehc/articles/1282350.html
我归纳一下就是:准备顶点和图元数据----》传到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:

Direct3D graphics pipeline diagram

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:

Direct3D system relationship diagram

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进行控制.混合以后的像素就被"画"到屏幕上了

你可能感兴趣的:(复习一下D3D渲染流程)