"Reprint" of the graphics pipeline about OpenGL

Source: Internet
Author: User

This article is reproduced from http://blog.csdn.net/racehorse/article/details/6593719 GLSL tutorial

This is a list of GLSL tutorials from Lighthouse3d, ideal for getting started. I will be learning while translating the content of the tutorial, at the same time recorded here, convenient for later query.

Pipeline Overview

Describes a simplified graphical processing pipeline, although it is simple but still can show some important concepts of shader programming (shader programming).

A fixed pipeline includes the following functions:

Vertex transformations (Vertex transformation)

Here a vertex is a collection of information, including the position in the space, the color of the vertex, the normals, the texture coordinates, and so on. The input of this phase is the independent vertex information, and the fixed function pipeline usually does the following work at this stage:

• Vertex position transformation

• Calculate lighting for each vertex

• Generation and transformation of texture coordinates

Primitive composition and rasterization (Primitive Assembly and Rasterization)

The input for this stage is the transformed vertex and connection information (connectivity information). The connection information tells the pipeline vertices how to make up entities (triangles, quads, and so on). This phase is also responsible for the viewing body (view frustum) cropping and back culling.

Rasterization determines the fragment (fragment), as well as the pixel position of the entity. The fragment here refers to a piece of data used to update a pixel in a particular position in the frame buffer. A fragment contains attributes such as normals and texture coordinates, in addition to colors, which are used to calculate new pixel color values.

The output of this phase includes:

• The location of the fragment in the frame cache

• The interpolation of the information computed during the vertex transformation phase to each fragment

This phase uses data from the vertex transformation phase to compute the fragment data in conjunction with the connection information. For example, each vertex contains a transformed position that can be used to calculate the fragment position of an entity when they make up an entity. Another example is the use of color, if each vertex of the polygon has its own color value, then the color value of the inner fragment of the polygon is the individual vertex color interpolation is worthwhile.

Fragment texturing and coloring (Fragment texturing and coloring)

The input to this stage is an interpolated fragment information. In the previous phase, texture coordinates and a color value have been computed by interpolation, which can be used to combine texture elements at this stage. In addition, this stage can also be atomized processing. Usually the final output is the color value of the fragment and the depth information.

Raster operation (Raster Operations)

Input for this stage:

• Pixel Location

• Fragment depth and color values

At this stage, a series of tests are performed on the fragments, including:

• Shear Testing (scissor test)

· Alpha Test

• Template Testing

• In-depth testing

If the test succeeds, the pixel values are updated with the fragment information based on the current blending mode (blend mode). Note that blending can only be done at this stage because the fragment texturing and color phase cannot access the frame cache. Frame caching can only be accessed at this stage.

A picture summarizes the fixed function pipeline (Visual Summary of the fixed functionality)

Visually summarize the various stages of the above pipeline:

Replace fixed function (replacing fixed functionality)

Now the graphics card allows programmers to program themselves to implement the two phases of the above pipeline:

• Vertex shader functions for the vertex transformation phase

• Fragment shader to replace fragment texturing and color functions

Vertex processor

The vertex processor is used to run the vertex shader (coloring program). The input to the vertex shader is the vertex data, i.e. position, color, normals, and so on.

The following OpenGL program sends data to the vertex processor, each vertex containing a color information and a location information.

Glbegin (...);    glcolor3f (0.2,0.4,0.6);    glvertex3f ( -1.0,1.0,2.0);    glcolor3f (0.2,0.4,0.8);    glvertex3f (1.0,-1.0,2.0); Glend ();

  

A vertex shader can write code to implement the following functions:

• Vertex transformations using the Model view matrix and the projection matrix

• Normal transformation and normalization

• Texture coordinate generation and transformation

• Per-vertex or per-pixel illumination calculation

• Color calculation

It is not necessary to complete all of the above actions, such as your program may not use lighting. However, once you have used vertex shader, all the fixed functions of the vertex processor will be replaced. So you can't just write the normal transform of the shader and expect the fixed function to help you finish the texture coordinate generation.

As already known from the previous section, the vertex processor does not know the connection information, so the operation of the topology information cannot be performed here. For example, a vertex processor cannot perform a back culling, it simply operates vertices rather than faces.

Vertex shader requires at least one variable: gl_position, which is typically transformed with a model view matrix and a projection matrix. The vertex processor can access the OpenGL state, so it can be used to work with materials and lighting. The latest devices also have access to textures.

Fragment processor

Fragment processor can run fragment shader, this unit can do the following:

• calculate color and texture coordinates per pixel

• Apply Textures

• atomization Calculation

• If pixel light is required, you can use it to calculate normals

The input of a fragment processor is a calculated interpolation of vertex coordinates, colors, normals, and so on. The property values for each vertex are computed in vertex shader, and each fragment in the entity is now processed, so the result of the interpolation is required.

As with the vertex processor, when you write the fragment shader, all the fixed functions will be replaced, so you cannot use the fragment shader to make the fragment material, while atomization with the fixed function. Programmers must write programs that implement all the effects they need.

The fragment processor operates independently of each fragment and does not know the contents of adjacent fragments. Similar to vertex shader, we must access the OpenGL state before we can know what fog colors are set in the application.

There are two kinds of outputs for a fragment shader:

• Discard the contents of a piece and output nothing

• Calculates the final color gl_fragcolor of the fragment and calculates the gl_fragdata when it is being rendered to multiple targets.

You can also write depth information, but the previous phase has been counted, so it is not necessary.

It should be emphasized that fragment shader cannot access the frame cache, so operations such as blend (blend) can only occur after this.

"Reprint" of the graphics pipeline about OpenGL

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.