16
16
17
17
package jp .co .cyberagent .android .gpuimage ;
18
18
19
+ import android .opengl .GLES20 ;
20
+
19
21
public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
20
22
21
23
public static final String LOOKUP_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n " +
@@ -24,17 +26,19 @@ public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
24
26
" uniform sampler2D inputImageTexture;\n " +
25
27
" uniform sampler2D inputImageTexture2; // lookup texture\n " +
26
28
" \n " +
29
+ " uniform lowp float intensity;\n " +
30
+ " \n " +
27
31
" void main()\n " +
28
32
" {\n " +
29
- " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n " +
33
+ " highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n " +
30
34
" \n " +
31
- " mediump float blueColor = textureColor.b * 63.0;\n " +
35
+ " highp float blueColor = textureColor.b * 63.0;\n " +
32
36
" \n " +
33
- " mediump vec2 quad1;\n " +
37
+ " highp vec2 quad1;\n " +
34
38
" quad1.y = floor(floor(blueColor) / 8.0);\n " +
35
39
" quad1.x = floor(blueColor) - (quad1.y * 8.0);\n " +
36
40
" \n " +
37
- " mediump vec2 quad2;\n " +
41
+ " highp vec2 quad2;\n " +
38
42
" quad2.y = floor(ceil(blueColor) / 8.0);\n " +
39
43
" quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n " +
40
44
" \n " +
@@ -50,11 +54,35 @@ public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
50
54
" lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);\n " +
51
55
" \n " +
52
56
" lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n " +
53
- " gl_FragColor = vec4(newColor.rgb, textureColor.w);\n " +
57
+ " gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity );\n " +
54
58
" }" ;
55
59
60
+ private int mIntensityLocation ;
61
+ private float mIntensity ;
56
62
57
63
public GPUImageLookupFilter () {
64
+ this (1.0f );
65
+ }
66
+
67
+ public GPUImageLookupFilter (final float intensity ) {
58
68
super (LOOKUP_FRAGMENT_SHADER );
69
+ mIntensity = intensity ;
70
+ }
71
+
72
+ @ Override
73
+ public void onInit () {
74
+ super .onInit ();
75
+ mIntensityLocation = GLES20 .glGetUniformLocation (getProgram (), "intensity" );
76
+ }
77
+
78
+ @ Override
79
+ public void onInitialized () {
80
+ super .onInitialized ();
81
+ setIntensity (mIntensity );
82
+ }
83
+
84
+ public void setIntensity (final float intensity ) {
85
+ mIntensity = intensity ;
86
+ setFloat (mIntensityLocation , mIntensity );
59
87
}
60
88
}
0 commit comments