Shader Notes (Rendering Pipeline)

  • The role of the rendering pipeline process: input 3D models and output 2D pictures.
Vertex processing, face processing, rasterization, pixel processing
  • Vertex Processing: Perform coordinate transformation and lighting calculations. Generate vertex coordinates, colors, texture coordinates that can be used for rendering into projected space. Through a series of coordinate system transformations, the vertices of the model are displaced in front of the camera, and finally projected onto the camera's projection screen. This stage of vertex transformation includes coordinate transformation of vertices, per-vertex fogging , material properties and lighting properties processing.

Local coordinate system: Centered on the model itself. For example, rotation, arm swing, etc. are based on the local coordinate system.
Observe the coordinate system: take the camera as the origin.
Observation coordinate system to projection coordinate system: The position of each object model is transferred from the observer's coordinate system to the observer's projection plane.

  • Face processing (usually engine processing)
Including face-to-face culling
Surface Assembly:
Usually Triangle Strip
Vertices outside the camera's view will be truncated.
Face culling 1. Seek normal judgment Front and back normal: The result of multiplying the two vectors of the surface is perpendicular to the two vectors, that is, the normal of the surface.
2. View frustum culling : remove the part of the surface outside the view frustum. (It is very close to the lens and very far away from the lens. Judgment method: each object has a Z value of the distance from the camera. It is judged by the depth buffer (Depth Buffer or Z-Buffer) provided by the hardware.

3. Occlusion culling : removes parts of faces that are covered behind other faces. Depth buffer support is also required. (The depth buffer is actually a layer of 0-255. Each time a pixel is rendered, the depth value of the current pixel will be detected. If the depth value of the current pixel is less than the depth value that has been stored, it means that the pixel is closer to the camera. is covered, and the depth value is updated to this pixel at this time.
  • 光栅化:以向量为基本结构的面转换成一个个点阵形式的像素
  • 像素处理:对每个像素区域进行着色,对像素贴上贴图。输入:像素的位置、深度、贴图坐标、法线、切线、颜色等。输出是每个像素的颜色、透明度。
  • 完整流程:

所有的渲染管线工作都是在GPU中进行,结果放在显存中,GPU每次输出一个 颜色值,放在 显存里,显存有交换链,显存每次输出一帧,后面一帧进行运算绘制,前面一帧显示完,后面一帧绘制完,进行交换,前面一帧缓存清空,再进行绘制。

固定管线:DX提供的渲染流程,很多地方没办法加入自己的算法,
可编程管线:Shader 可以加入自己的算法


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324400221&siteId=291194637