Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Overview of GPU rendering pipeline

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

1. Vertex shader

The vertex shader is the first stage of the pipeline, and its input comes from CPU. Vertex shaders are processed in vertices, which means that each vertex entered is called once.

The main tasks that vertex shaders need to complete are coordinate transformation and lighting per vertex. Of course, in addition to these two main tasks, vertex shaders can also output the data needed for subsequent stages.

Coordinate transformation, as the name implies, is some kind of transformation of the coordinates of vertices. For example, we can simulate water surface, cloth and so on by changing the position of vertices.

One of the tasks that a basic vertex shader must do is to transform vertex coordinates from model space to homogeneous clipping space. Code similar to the following:

O.pos=mul (UNITY_MVP,v.position); 2. Cut out

Since our scene may be very large, and the field of view of the camera may not cover all the objects in the scene, it is a natural idea that those objects that are not in the field of view of the camera do not need to be processed. Cutting is proposed to achieve this purpose.

There are three relationships between an element and a camera:

Completely in view

Partly in the field of vision.

Completely in the visual field.

Some elements in the field of view need to be cropped, for example, one vertex of a line segment is in the field of view, and the other vertex is out of view, then the vertex outside the field of view should be replaced by a new vertex, which is located at the intersection of the line segment and the boundary of the field of view.

3. Screen mapping

The coordinates entered in this step are still three-dimensional coordinate system. The task of screen mapping is to convert the x and y coordinates of each element to the screen coordinate system, which is a two-dimensional coordinate system, which has a lot to do with the resolution we use to display the picture.

The screen coordinates obtained by the screen mapping determine which pixel the vertex corresponds to on the screen and how far away it is from that pixel.

The origin of the screen coordinates of the opengl is the lower left corner, while the directx is the upper left corner. If you find that the image you get is inverted, it is likely to be caused by this.

4. Triangle Settin

From this step, we enter the rasterization phase. the information output from the previous stage is the position of the vertices in the screen coordinates and the additional information related to them, such as depth value, normal direction, viewing angle direction, and so on. Rasterization has two most important goals: to calculate which pixels are covered by each element, and to calculate their color for those pixels. The first pipelining phase of rasterization is triangle setup, which calculates the information needed to rasterize a triangular mesh.

Specifically, the output of the previous stage is the vertices of the triangular mesh, that is, we get the two endpoints of each edge of the triangular mesh. But if we want to get the pixel coverage of the entire triangular mesh, we have to calculate the pixel coordinates on each edge. In order to calculate the coordinate information of the boundary pixels, we need to get the representation of the triangle boundary. Such a process of calculating the data represented by a triangular mesh is called triangle setting, and its output is in preparation for the next stage.

5. Triangle traversal

The triangle traversal phase will check whether each pixel is covered by a triangular mesh. If it is covered, a slice will be generated, and such a process of finding which pixels are covered by the triangular mesh is triangle traversal, which is also known as scan transformation.

The triangle traversal stage determines which pixels are covered by a triangular mesh according to the calculation results of the previous stage, and uses the vertex information of the three vertices of the triangular mesh to interpolate the pixels of the whole coverage area.

6. Chip element shader

The chip element shader is another very important programmable shader stage. the input of the chip element shader is the result of interpolation of vertex information in the previous stage, or more specifically, based on the data output from the vertex shader. Its output is one or more color values.

Many important rendering techniques can be completed at this stage, one of the most important of which is texture sampling. In order to sample the texture in the chip shader, we usually output the texture coordinates corresponding to each vertex in the vertex shader stage, and then interpolate the texture coordinates corresponding to the three vertices of the triangular mesh after the rasterization stage. the texture coordinates of the covered elements can be obtained.

7. Piece-by-piece operation

Piece-by-piece meta-operation is a term in opengl, and in directx, this phase is called the output merge phase.

There are several main tasks at this stage:

Determines the visibility of the element. Involves a lot of testing work, such as in-depth testing, template testing and so on.

If an element passes all the tests, you need to merge the color value of the element with the color already stored in the color buffer.

At this point, the entire GPU rendering pipeline is over.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report