Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. package Filters;
  2.  
  3. import android.opengl.GLES20;
  4.  
  5. import com.owner.glitchee.CameraActivity;
  6.  
  7. import cn.ezandroid.ezfilter.core.FilterRender;
  8.  
  9. public class gba1 extends FilterRender {
  10.  
  11.     private static final String UNIFORM_WIDTH = "width";
  12.     private int mWidthHandler;
  13.     private static final String UNIFORM_HEIGHT = "height";
  14.     private int mHeightHandler;
  15.     private String UNIFORM_AMOUNT = "amount";
  16.     private int mAmountHandler;
  17.     private static float mAmount;
  18.     private static float mUpdatedAmount = (float) 30.0;
  19.  
  20.     public gba1() {
  21.         setFragmentShader(
  22.                 "precision mediump float;\n"+
  23.                         "varying lowp vec2 textureCoordinate;\n"+
  24.                         "uniform sampler2D inputImageTexture;\n"+
  25.                         "uniform float amount;\n"+
  26.                         "uniform float width;\n"+
  27.                         "uniform float height;\n"+
  28.  
  29.                         "#define iResolution vec2(width,height)\n"+
  30.                         "#define GB_RESOLUTION amount\n"+
  31.                         "#define GB_SOURCE_ADD -0.267\n"+
  32.                         "#define GB_SOURCE_POWER 0.5\n"+
  33.                         "void main(){\n"+
  34.                         "vec2 uv = textureCoordinate.xy * GB_RESOLUTION;\n"+
  35.                         "if (uv.x <= 1. && uv.y <= 1.) {\n"+
  36.                         "vec4 color = texture2D(inputImageTexture, uv);\n"+
  37.                         "float gray = (color.r * 0.8 + color.g * 1.0 + color.b * 0.9) / 2.7;\n"+
  38.                         "gray = pow(clamp(gray + GB_SOURCE_ADD, 0., 1.), GB_SOURCE_POWER);\n"+
  39.                         "//gray = uv.x; // to test the dithering more easily\n"+
  40.                         "gl_FragColor = vec4(gray, gray, gray, 1.);\n"+
  41.                         "} else {\n"+
  42.                         "gl_FragColor = vec4(0,0,0,1);\n"+
  43.                         "}\n"+
  44.                         "}"
  45.  
  46.         );
  47.     }
  48.  
  49.     @Override
  50.     protected void initShaderHandles() {
  51.         super.initShaderHandles();
  52.         mAmountHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_AMOUNT);
  53.         mWidthHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_WIDTH);
  54.         mHeightHandler = GLES20.glGetUniformLocation(mProgramHandle, UNIFORM_HEIGHT);
  55.     }
  56.  
  57.     @Override
  58.     protected void bindShaderValues() {
  59.         super.bindShaderValues();
  60.         GLES20.glUniform1f(mAmountHandler, mAmount);
  61.         GLES20.glUniform1f(mWidthHandler, CameraActivity.mRenderPipeline.getWidth());
  62.         GLES20.glUniform1f(mHeightHandler, CameraActivity.mRenderPipeline.getHeight());
  63.     }
  64.  
  65.     @Override
  66.     protected void onDraw() {
  67.         super.onDraw();
  68.         mAmount = mUpdatedAmount;
  69.     }
  70.  
  71.     public static void setAmount(float amount){
  72.         mUpdatedAmount = (amount);
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement