Introduction to OpenGL vsh and fstms + cocos2dx 3.0 shader grayed out

Source: Internet
Author: User
Recognize the coloring erThe OpenGL ES coloring tool contains two files:. FSH and. vsh. After the two files are compiled and linked, the executable program can interact with the GPU .. Vsh is the vertex shader. It is used for vertex calculation to understand the position of the control vertex. In this file, we usually input the position of the current vertex and the coordinate of the texture. For example:
 1 attribute vec4 position;  2 attribute vec4 inputTextureCoordinate; 3  4 varying vec2 textureCoordinate; 5  6 precision mediump float; 7 uniform float overTurn; 8  9 void main()10 {11 gl_Position = position;12     if (overTurn>0.0) {13         textureCoordinate = vec2(inputTextureCoordinate.x,overTurn-inputTextureCoordinate.y);14     }15     else16         textureCoordinate = vec2(inputTextureCoordinate.x,inputTextureCoordinate.y);17 }

Attribute: the variable that passes in the vsh file externally. The variable change rate of each frame rendering is high, which is used to define each vertex.

Varying: a parameter used to pass between vsh and fst4.

Precision mediump float defines a floating point with medium precision.

The variable change rate of the externally passed vsh file in the uniform is low. It may be a constant if it is not changed throughout the rendering process.

When the overturn value in main () is greater than 0, what is done in the function is to reverse the Y axis of the texture.

. Shader is the clip. Here I can re-calculate each pixel to achieve the filter effect.

 1 varying highp vec2 textureCoordinate; 2 precision mediump float; 3 uniform sampler2D videoFrame; 4  5 vec4 memoryRender(vec4 color) 6 { 7     float gray; 8     gray = color.r*0.3+color.g*0.59+color.b*0.11; 9     color.r = gray;10     color.g = gray;11     color.b = gray;12     13     color.r += color.r*1.5;14     color.g = color.g*2.0;15     16     if(color.r > 255.0)17     color.r = 255.0;18     if(color.g > 255.0)19     color.g = 255.0;20     21     return color;22 }23 24 void main()25 {26     vec4 pixelColor;27 28     pixelColor = texture2D(videoFrame, textureCoordinate);29     30     gl_FragColor = memoryRender(pixelColor);31 }

Varying highp vec2 texturecoordinate is the texture coordinate transmitted from vsh.

Uniform sampler2d videoframe is our true texture map.

Texture2d (videoframe, texturecoordinate) extracts the color of each pixel in the texture to pixelcolor.

You can use memoryrender (pixelcolor) to re-process the obtained pixel.

Summary:

It is not very difficult to program the shader. It is entirely the C syntax. However, debugging is troublesome and the type constraints are strict. Only the same type can be used for arithmetic operations. After understanding these two files, we can use our imagination to process texture images.

Someone else concluded:

Vsh is responsible for handling the pixel location, filling in the gl_posizion variable, occasionally fixing the point size problem, and filling in the gl_pixelsize.

FGS is responsible for handling the pixel appearance, filling in gl_fragcolor, and occasionally filling in another set of variables.

They all run once per pixel or multiple times. We strive to calculate this pixel.

 

Introduction to OpenGL vsh and fstms + cocos2dx 3.0 shader grayed out

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.