-
Notifications
You must be signed in to change notification settings - Fork 89
/
CrossProcessEffect.java
38 lines (32 loc) · 1.7 KB
/
CrossProcessEffect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.sherazkhilji.videffects;
import android.opengl.GLSurfaceView;
import com.sherazkhilji.videffects.interfaces.ShaderInterface;
/**
* Applies a cross process effect on video, in which the red and green channels
* are enhanced while the blue channel is restricted.
*
* @author sheraz.khilji
*/
public class CrossProcessEffect implements ShaderInterface {
@Override
public String getShader(GLSurfaceView mGlSurfaceView) {
return "#extension GL_OES_EGL_image_external : require\n"
+ "precision mediump float;\n"
+ "uniform samplerExternalOES sTexture;\n"
+ "varying vec2 vTextureCoord;\n" + "void main() {\n"
+ " vec4 color = texture2D(sTexture, vTextureCoord);\n"
+ " vec3 ncolor = vec3(0.0, 0.0, 0.0);\n" + " float value;\n"
+ " if (color.r < 0.5) {\n" + " value = color.r;\n"
+ " } else {\n" + " value = 1.0 - color.r;\n" + " }\n"
+ " float red = 4.0 * value * value * value;\n"
+ " if (color.r < 0.5) {\n" + " ncolor.r = red;\n"
+ " } else {\n" + " ncolor.r = 1.0 - red;\n" + " }\n"
+ " if (color.g < 0.5) {\n" + " value = color.g;\n"
+ " } else {\n" + " value = 1.0 - color.g;\n" + " }\n"
+ " float green = 2.0 * value * value;\n"
+ " if (color.g < 0.5) {\n" + " ncolor.g = green;\n"
+ " } else {\n" + " ncolor.g = 1.0 - green;\n" + " }\n"
+ " ncolor.b = color.b * 0.5 + 0.25;\n"
+ " gl_FragColor = vec4(ncolor.rgb, color.a);\n" + "}\n";
}
}