Shader and Shader image processing, Shader Demo

  There are many filter effects in android-gpuimage, and the essence is to process images with shaders.
  Using OpenGL for image processing, the most important thing is the realization of FragShader. The following are several shaders that have been implemented. There are black and white photo processing, Sephia special effects, inversion, Gaussian blur, Median blur, sharpening, corrosion, expansion, Laplacian edge detection, etc.

- Android platform OpenGL SE Camera filter implementation Demo- https://github.com/andev009/AndroidShaderDemo
Image processing based on Shader for Android platform
``Android platform OpenGL SE Camera filter implementation'
' ` `Android Shader-based image processing (1 )-Grayscale and Convolution"
"Android Shader-based image processing (2 )-Frame buffer object FBO"
"Android Shader-based image processing (3
)-Mosaic " "Android Shader-based image processing (4)-Sobel Edge Detection"
"Android Shader-based image processing (5)-Canny edge detection"
"Android Shader-based image processing (6)-Camera development"
"Android Shader-based image processing (7) -color table LUT"
"Android based Shader's image processing (8)-imitating vibrato zoom special effects"
"Android Shader-based image processing (9)-imitating vibrato flashing white effects"
"Android Shader-based image processing (10)-imitating vibrato glitch effects"
" Android Shader-based image processing (11)-imitating the soul of vibrato"
"Android Shader-based image processing (12)-imitating vibrato shake special effects"
"Android Shader-based image processing (13)-camera split screen preview"
"Android Shader-based Image Processing (14)-Tik Tok Split Screen Preview"
"Android Native Layer OpenGL ES Development"
"Android Java Layer Encapsulation EGL"

- Starting from Cocos2d-x 2.x version, the underlying graphics rendering of Cocos2d-x uses OpenGL ES2.x new feature programmable shader (Shader),
the use process of Shader:
1. Create shader object: glCreateShader
2. Shader Object associated shader code: glShaderSource
3. Compile the shader source code into the target code: glCompileShader
4. Verify that the shader has been mutated: glGetShaderiv, glGetShaderInfoLog
5. Create a shader program: glCreatePragram
6. Link the shader to the shader In the program: glAttachShader
7, link shader program: glLinkProgram
8, verify that the shader program is successfully linked: glGetProgramiv, glGetProgramInfoLog
9, use the shader program for fixed-point or fragment processing: glUseProgram

- Shader Arithmetic
• The vertex processor works based on 32-bit floating point values: Vertex Shader uses floating point to represent integers. In order to avoid 32-bit values, set the output varing precision of the Vertex Shader program to mediump or lowp.
• Fragment Shader uses a 16-bit floating point value to work: its composition is: sign; 5-bit exponent to offset 15; 10-bit mantissa, with an implicit most significant 1 bit

- Shader optimization , the Shader code implements our algorithm. If you want to greatly reduce the time consumption of the Shader, it is the most effective way to reduce the image quality and reduce the amount of calculation. To optimize on the basis of ensuring quality as much as possible, there are generally these methods:
(1) Avoid using loops or branch judgment statements in the Shader
(2) Avoid relying on texture reading. That is, avoid calculating texture coordinates in Fragment Shader and advance the calculation to Vertex Shader to reduce the number of calculations.
(3) Avoid exchanging texture coordinate components. This will cause dependent texture reading.
(4) Avoid doing data calculations such as pow in Fragment Shader. Similarly, advance the calculation to the Vertex Shader as much as possible, reduce the number of calculations
(5) and use fewer color components to participate in the calculation. Select the main color components that affect the result to participate in the calculation, which is also an effective way to reduce the amount of calculation.
(6) Reduce data accuracy. For example, changing the texture coordinate accuracy passed from Vertex Shader to Fragment Shader from highp to mediump will also reduce some consumption.

Guess you like

Origin blog.csdn.net/ShareUs/article/details/94922493