Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Filters;
- import android.opengl.GLES20;
- import com.owner.glitchee.CameraActivity;
- import cn.ezandroid.ezfilter.core.FilterRender;
- public class gba1 extends FilterRender {
- private static final String UNIFORM_WIDTH = "width";
- private int mWidthHandler;
- private static final String UNIFORM_HEIGHT = "height";
- private int mHeightHandler;
- private String UNIFORM_AMOUNT = "amount";
- private int mAmountHandler;
- private static float mAmount;
- private static float mUpdatedAmount = (float) 30.0;
- public gba1() {
- setFragmentShader(
- "precision mediump float;\n"+
- "varying lowp vec2 textureCoordinate;\n"+
- "uniform sampler2D inputImageTexture;\n"+
- "uniform float amount;\n"+
- "uniform float width;\n"+
- "uniform float height;\n"+
- "#define iResolution vec2(width,height)\n"+
- "#define GB_RESOLUTION amount\n"+
- "#define GB_SOURCE_ADD -0.267\n"+
- "#define GB_SOURCE_POWER 0.5\n"+
- "void main(){\n"+
- "vec2 uv = textureCoordinate.xy * GB_RESOLUTION;\n"+
- "if (uv.x <= 1. && uv.y <= 1.) {\n"+
- "vec4 color = texture2D(inputImageTexture, uv);\n"+
- "float gray = (color.r * 0.8 + color.g * 1.0 + color.b * 0.9) / 2.7;\n"+
- "gray = pow(clamp(gray + GB_SOURCE_ADD, 0., 1.), GB_SOURCE_POWER);\n"+
- "//gray = uv.x; // to test the dithering more easily\n"+
- "gl_FragColor = vec4(gray, gray, gray, 1.);\n"+
- "} else {\n"+
- "gl_FragColor = vec4(0,0,0,1);\n"+
- "}\n"+
- "}"
- );
- }
- @Override
- protected void initShaderHandles() {
- super.initShaderHandles();
- mAmountHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_AMOUNT);
- mWidthHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_WIDTH);
- mHeightHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_HEIGHT);
- }
- @Override
- protected void bindShaderValues() {
- super.bindShaderValues();
- GLES20.glUniform1f(mAmountHandler, mAmount);
- GLES20.glUniform1f(mWidthHandler, CameraActivity.mRenderPipeline.getWidth());
- GLES20.glUniform1f(mHeightHandler, CameraActivity.mRenderPipeline.getHeight());
- }
- @Override
- protected void onDraw() {
- super.onDraw();
- mAmount = mUpdatedAmount;
- }
- public static void setAmount(float amount){
- mUpdatedAmount = (amount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement