OpenGL ES /OpenGL ES /OpenGL ES /OpenGL ES /OpenGL ES Image rendering implementation and rendering problems OpenGL/OpenGL ES introduction: basic transformation – beginning vector/matrix OpenGL/OpenGL ES introduction: texture exploration – common API parsing OpenGL/OpenGL ES introduction: OpenGL/OpenGL ES: Vertex shaders and slice shaders (OpenGL transition OpenGL ES) Introduction to OpenGL/OpenGL ES: GLKit usage and case studies

This goal

  • OpenGL rendering flow chart analysis

  • OpenGL fixed storage shader understanding

OpenGL rendering process

As shown in the figure above, the pipeline is divided into two parts: the top part is the client side and the bottom part is the server side. The server side and the client side function and run asynchronously, as separate software blocks and hardware blocks.

In the programmable pipeline, we can code the Vertex Shader and Fragment Shader, which are the two necessary shaders for rendering.

Vertex shaders process data input from clients, apply transformations, and perform other types of math to calculate lighting effects, shifts, and color values. To render a triangle with three vertices, the Vertex Shader executes three times, one for each Vertex.

The Primitive Assembly in the image shows that the three vertices have been grouped together and the triangle has been rasterized fragment by fragment. Each Fragment is populated by executing the Fragment Shader. The Fragment Shader will output the final color values we will see on the screen.

  • Attribute: is a data element that changes each vertex. In fact, the vertex position itself is a property. Attributes can be floating point, integer, or Boolean data.

  • Uniform values: Usually setting the Uniform variable is followed by issuing the render a pixel batch command. Unlimited use. Set a single color value to be applied to the entire surface, and you can also set a time value. It can be floating point, integer, or Boolean data.

  • Texture data: Both Vertex Shader and Fragment Shader can sample and filter texture values. Texture data does more than just represent graphics (more on that later).

  • Output: Output data is defined as the output of a stage shader, while shaders in subsequent stages are defined as inputs (in). Output type data can be simply passed from one stage to the next or inserted in different ways. Variables that cannot be touched by client code.

3 ways to pass render data to OpenGL shaders: 1. Attributes 2. Uniform values 2

Note: Attributes cannot be passed directly to the Fragment Shader. If passed to the Fragment Shader, they must be passed indirectly through the Vertex Shader. The Unifrom and Texture Data can be passed directly to the Vertex Shader and Fragment Shader depending on your needs.

Fixed storage shader classification

Use of storage shaders

Initialization of GLShaderManager

GLShaderManager initializes GLShaderManager; shaderManager.InitializeStockShaders();Copy the code

Identity shader

GLShaderManager::UseStockShader(GLT_SHADER_IDENTITY, GLfloat vColor[4]);
Copy the code

Unit shader: Simply use the default Cartesian coordinate system (range -1.0 to 1.0). All the fragments are applied the same color and the geometry is solid and unrendered. Parameter 1: Storage shader type – Unit shader Parameter 2: color

Flat shader

GLShaderManager::UseStockShader(GLT_SHADER_FLAT, FLfloat mvp[16], GLfloat vColor[4]);
Copy the code

Flat shader: Extends the uniform shader to allow a 4×4 transformation matrix to be specified for geometric transformations. When drawing, transformations (model/projection changes) can be applied. Parameter 1: Storage shader type – Flat shader Parameter 2: 4×4 matrix parameter 3: color

Shaded (Shaded) shader

GLShaderManager::UseStockShader(GLT_SHADER_SHADED, GLfloat mvp[16]);
Copy the code

Coloring shader: The only uniform value of this shader is the transformation matrix applied to geometric shapes. Both GLT_ATTRIBUTE_VERTEX(vertex component) and GLT_ATTRIBUTE_COLOR(color component) are used in this shader. Color values are inserted smoothly between vertices (called smooth shading). Parameter 1: Store shader type – Coloring shader Parameter 2: allow variable 4×4 matrix

Default light shader

GLShaderManager::UseStockShader(GLT_SHADER_DEFAULT_LIGHT, FLfloat mvMatrix[16],GLfloat pMatrix[16], GLfloat vColor[4]);
Copy the code

Default light shader: shadows and illuminates objects. GLT_ATTRIBUTE_VERTEX(vertex components) and GLT_ATTRIBUTE_NORMAL(surface normals) need to be set to store the shader. Parameter 1: Storage shader type – Default light shader parameter 2: model 4×4 matrix parameter 3: projection 4×4 matrix parameter 4: color

Point light shader

GLShaderManager::UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, FLfloat mvMatrix[16],GLfloat pMatrix[16],GLfloat vLightPos[3], GLfloat vColor[4]);
Copy the code

Point light shader: Point light shader is similar to the default light shader, but the light position may be specific. Also set GLT_ATTRIBUTE_VERTEX(vertex components) and GLT_ATTRIBUTE_NORMAL(surface normals) to store shaders. Parameter 1: Storage shader type – Point shader parameter 2: model 4×4 matrix parameter 3: projection 4×4 matrix parameter 4: point shader position parameter 5: color

Texture replacement matrix shader

GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_REPLACE, GLfloat mvpMatrix[16], GLint nTextureUnit);
Copy the code

Texture replacement matrix shader: Transforms the geometry of the texture bound to the texture unit specified by nTextureUnit by projecting a matrix to the given model view. Fragment color is obtained directly from the texture sample. The required attributes are GLT_ATTRIBUTE_VERTEX(vertex component) and GLT_ATTRIBUTE_NORMAL(surface normal). Parameter 1: Store shader type – Texture replacement matrix Shader parameter 2: model 4×4 matrix parameter 3: texture unit

Texture adjustment shader

GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_MODULATE, GLfloat mvpMatrix[16], GLfloat vColor, GLint nTextureUnit);
Copy the code

Texture adjustment shader: Multiply a base color by a texture taken from the texture unit nTextureUnit. The required attributes are GLT_ATTRIBUTE_VERTEX(vertex components) and GLT_ATTRIBUTE_TEXTURE0(texture coordinates). Parameter 1: Store shader type – Texture adjustment shader Parameter 2: model 4×4 matrix parameter 3: color value parameter 4: texture unit

Texture light shader

GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, GLfloat mvMatrix, GLfloat pMatrix[16], GLfloat vLightPos[3], GLfloat vBaseColor[4], GLint nTextureUnit);
Copy the code

Light texture shaders: will a texture to adjust by diffuse lighting calculation (multiply), the position of guangxi in the visual space is given, the shader accepts five Uniform value, namely the model view matrix and projection matrix, the visual space of the light source location, the geometry of basic color and texture units will be used. The required attributes are GLT_ATTRIBUTE_VERTEX(vertex components), GLT_ATTRIBUTE_TEXTURE0(texture coordinates), and GLT_ATTRIBUTE_NORMAL(surface normals). Parameter 1: Store shader type – Texture shader parameter 2: model 4×4 matrix parameter 3: projection 4×4 matrix parameter 4: point light source position parameter 5: color value (basic color of geometry) parameter 6: texture unit