Skip to content

Commit 245d050

Browse files
committed
Merge pull request cats-oss#202 from jonan/lookup-intensity
GPUImageLookupFilter updated
2 parents adac59c + 036176a commit 245d050

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

library/src/jp/co/cyberagent/android/gpuimage/GPUImageLookupFilter.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package jp.co.cyberagent.android.gpuimage;
1818

19+
import android.opengl.GLES20;
20+
1921
public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
2022

2123
public static final String LOOKUP_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
@@ -24,17 +26,19 @@ public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
2426
" uniform sampler2D inputImageTexture;\n" +
2527
" uniform sampler2D inputImageTexture2; // lookup texture\n" +
2628
" \n" +
29+
" uniform lowp float intensity;\n" +
30+
" \n" +
2731
" void main()\n" +
2832
" {\n" +
29-
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
33+
" highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
3034
" \n" +
31-
" mediump float blueColor = textureColor.b * 63.0;\n" +
35+
" highp float blueColor = textureColor.b * 63.0;\n" +
3236
" \n" +
33-
" mediump vec2 quad1;\n" +
37+
" highp vec2 quad1;\n" +
3438
" quad1.y = floor(floor(blueColor) / 8.0);\n" +
3539
" quad1.x = floor(blueColor) - (quad1.y * 8.0);\n" +
3640
" \n" +
37-
" mediump vec2 quad2;\n" +
41+
" highp vec2 quad2;\n" +
3842
" quad2.y = floor(ceil(blueColor) / 8.0);\n" +
3943
" quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n" +
4044
" \n" +
@@ -50,11 +54,35 @@ public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
5054
" lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);\n" +
5155
" \n" +
5256
" 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" +
5458
" }";
5559

60+
private int mIntensityLocation;
61+
private float mIntensity;
5662

5763
public GPUImageLookupFilter() {
64+
this(1.0f);
65+
}
66+
67+
public GPUImageLookupFilter(final float intensity) {
5868
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);
5987
}
6088
}

0 commit comments

Comments
 (0)