Skip to content

Commit f75207c

Browse files
jonanJon Ander Peñalba
authored andcommitted
Add intensity property to GPUImageLookupFilter
1 parent 6a7c30b commit f75207c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
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,6 +26,8 @@ public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
2426
" uniform sampler2D inputImageTexture;\n" +
2527
" uniform sampler2D inputImageTexture2; // lookup texture\n" +
2628
" \n" +
29+
" uniform float intensity;\n" +
30+
" \n" +
2731
" void main()\n" +
2832
" {\n" +
2933
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\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)