OpenGL ES 2.0 Basic Concepts

Source: Internet
Author: User

1. OpenGL ES 2.0 Programmable Piping

OpenGL is responsible for converting objects in three-dimensional space into two-dimensional images by projecting, rasterization, and then rendering to the screen.


The yellow section (Vertex Shader and Fragment Shader) is the programmable part of this pipeline. The entire pipeline consists of the following two specifications:

1) OpenGL ES 2.0 API Specification

2) OpenGL ES Shading Language specification (OpenGL ES SL)

The detailed flowchart is as follows:

This process transforms the three-dimensional data into two-dimensional data that can be displayed.

2. Shader (Just a program)

Shader is a program that executes on the GPU (so Shader can also be called the program), which is written using the OpenGL ES SL language. It is a simple program that describes vertex or pixel attributes.

2.1 Pixel Shader

The Pixel Shader (Pixel shader) is the well-known fragment Shader, which calculates the color and other properties of each pixel. It calculates the color of the pixel and outputs it by applying lighting values, bump maps, shadows, specular highlights, translucency , and so on. It can also change the depth of the pixel (z-buffering) or output multiple colors in a state where multiple render targets are activated. A pixel shader cannot produce complex effects because it operates on only one pixel without knowing the geometry of the scene.

2.2 Vertex Shader

For each vertex (vertex) sent to the GPU, a vertex Shader (vertex shader) is performed once. Its function is to transform the three-dimensional coordinates of each vertex in the virtual space into two-dimensional coordinates that can be displayed on the screen, with depth information for z-buffer. Vertex shader properties that can be manipulated are: position, color, texture coordinates , but cannot create new vertices.

Vertex shader input data as follows:

1)Attributes: each vertex data provided through the vertex array (vertex arrays)

2)Uniforms: constant data used by Vertex shader
3)samplers: Vertex shader uses a uniforms that represents the texture type, which is optional in Vertex shader

4)Shader program: Vertex Shader The source code or executable file that describes the actions that will be performed on the vertex

The Vertex shader output is:varying variables (Vertex shader output variable, as input to fragment shader. must correspond to input varying one by one in fragment shader. )

gl_position: is the intrinsic varying of each point, representing the spatial position of the point.

A Vertex Shader Example:

 //uniforms used by the vertex shader
 uniform mat4 U_mvpmatrix;//Matrix T o convert P from model
                                                /space to normalized device Space.
 //attributes input to the vertex shader
attribute vec4 a_position;  //Position value
Attribu Te vec4 a_color;      //input vertex color
//varying variables–input to the fragment Shader
Varying VEC4 v_color;       //output vertex color
 void   main ()
 {
      v_color = A_color;
      gl_position = U_mvpmatrix * a_position;
}  

2.3 Geometry Shader

Geometry Shader is a relatively new type of Shader. It is introduced in Driect3d 10 and OpenGL 3.2 and is used as an extension in the Openggl 2.0+. Its input is point, line, and triangle, and its output is point, line band and Triangle Band.

The Geometry shader program executes after the vertex shader program executes.

3. Shading Language

Glsl:shading language developed for use with OpenGL
HLSL: Shading Language developed for use with the Direct3D API

Shading Language is only suitable for GPU programming, programming tools for CG (NVIDIA development), CG compilers can to output direct3x or OpenGL shader programs.

4. Shading Algorithm

4.1 Interpolation technology (can be combined with any lighting model):
? Flat Shading
? Gouraud Shading
? Phong Shading
4.2 Illumination model (can be combined with any interpolation technology):

       blinn–phong
       cook–torrance (microfacets)  
       lambert 
       minnaert 
       oren–nayar (Rough opaque diffuse surfaces)  
       phong 
       ward anisotropic

5. Original language compilation (Primitive Assembly)

In the pipeline (pipeline), after the vertex shader is executed, the original language is compiled. A primitive (primitive) is a geometric object that can be drawn using the OpenGL ES Paint command.

At the primitive assembly stage, vertices that were processed by the vertex shader are combined to make a separate geometric primitive (such as points, lines, and triangles) that can be drawn. Then perform the following two actions on the geometry primitive:

?  Clipping (cropping): primitives that remain only within the visual space

? Culling (selection): Base language selection based on pre-or post-orientation

After cropping and selection, its next stage is geometry Shader (if present) or rasterized.
6. Grating (rasterization)

Target of raster processing: Convert Primitives to a series of two-dimensional fragments, these two-dimensional fragments will be processed by fragment shader, and these two-dimensional fragments represent pixels that can be drawn on the screen.

7. Fragment Shader
Perform a fragment Shader for each fragment produced by the rasterization, with the following input:

? The output of the Varying Variables:vertex shader is generated by using the interpolation method for each fragment by the Rasterization unit
? UNIFORMS:FRAGMENT constant data used by shader
? Samplers: A constant data that represents a texture
? Shader program:fragment Shader Program source code or executable file that describes the actions that will be performed on the Fragment.

Fragment shader either discards this Fragment, or generates a corresponding color for this Fragment, and saves it in Gl_fragcolor.

A Fragment Shader Example:
Precision Mediump float;
Varying VEC4 v_color; Input vertex color from vertex shader
void
Main (void)
{
Gl_fragcolor = V_color;
}

8. Per-fragment Operations

After Fragment shader is executed, its next process is per-fragment operation. The processing flow is as follows:

The result of executing the per-fragment operation is discarded for this Fragment, or the Xw,yw color value is written in the framebuffer corresponding position (Fragment) , or the depth value or The stencil value .



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

OpenGL ES 2.0 Basic Concepts

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.