Android Open Source - FxCameraApp Gl Convolution Shader From Project Back to project page FxCameraApp .
License The source code is released under:
MIT License
If you think the Android project FxCameraApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.af.experiments.FxCameraApp.shaders;
public class GlConvolutionShader extends GlShader {
/ * w w w . j a v a 2 s . c o m * /
private static final String VERTEX_SHADER =
"attribute vec4 aPosition;" +
"attribute vec4 aTextureCoord;" +
"highp float texelWidth = 1.0 / 1024.;;" +
"highp float texelHeight = 1.0 / 728.;" +
"varying vec2 textureCoordinate;" +
"varying vec2 leftTextureCoordinate;" +
"varying vec2 rightTextureCoordinate;" +
"varying vec2 topTextureCoordinate;" +
"varying vec2 topLeftTextureCoordinate;" +
"varying vec2 topRightTextureCoordinate;" +
"varying vec2 bottomTextureCoordinate;" +
"varying vec2 bottomLeftTextureCoordinate;" +
"varying vec2 bottomRightTextureCoordinate;" +
"void main() {" +
"gl_Position = aPosition;" +
"vec2 widthStep = vec2(texelWidth, 0.0);" +
"vec2 heightStep = vec2(0.0, texelHeight);" +
"vec2 widthHeightStep = vec2(texelWidth, texelHeight);" +
"vec2 widthNegativeHeightStep = vec2(texelWidth, -texelHeight);" +
"textureCoordinate = aTextureCoord.xy;" +
"leftTextureCoordinate = textureCoordinate.xy - widthStep;" +
"rightTextureCoordinate = textureCoordinate.xy + widthStep;" +
"topTextureCoordinate = textureCoordinate.xy - heightStep;" +
"topLeftTextureCoordinate = textureCoordinate.xy - widthHeightStep;" +
"topRightTextureCoordinate = textureCoordinate.xy + widthNegativeHeightStep;" +
"bottomTextureCoordinate = textureCoordinate.xy + heightStep;" +
"bottomLeftTextureCoordinate = textureCoordinate.xy - widthNegativeHeightStep;" +
"bottomRightTextureCoordinate = textureCoordinate.xy + widthHeightStep;" +
"}" ;
private static final String FRAGMENT_SHADER =
"precision highp float;" + // ?????????????????
"uniform lowp sampler2D sTexture;" +
"mediump mat3 convolutionMatrix = mat3( 0., 0., 0., 0., 1., 0., 0., 0., 0.);" +
"varying vec2 textureCoordinate;" +
"varying vec2 leftTextureCoordinate;" +
"varying vec2 rightTextureCoordinate;" +
"varying vec2 topTextureCoordinate;" +
"varying vec2 topLeftTextureCoordinate;" +
"varying vec2 topRightTextureCoordinate;" +
"varying vec2 bottomTextureCoordinate;" +
"varying vec2 bottomLeftTextureCoordinate;" +
"varying vec2 bottomRightTextureCoordinate;" +
"void main() {" +
"mediump vec4 bottomColor = texture2D(sTexture, bottomTextureCoordinate);" +
"mediump vec4 bottomLeftColor = texture2D(sTexture, bottomLeftTextureCoordinate);" +
"mediump vec4 bottomRightColor = texture2D(sTexture, bottomRightTextureCoordinate);" +
"mediump vec4 centerColor = texture2D(sTexture, textureCoordinate);" +
"mediump vec4 leftColor = texture2D(sTexture, leftTextureCoordinate);" +
"mediump vec4 rightColor = texture2D(sTexture, rightTextureCoordinate);" +
"mediump vec4 topColor = texture2D(sTexture, topTextureCoordinate);" +
"mediump vec4 topRightColor = texture2D(sTexture, topRightTextureCoordinate);" +
"mediump vec4 topLeftColor = texture2D(sTexture, topLeftTextureCoordinate);" +
"mediump vec4 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2];" +
"resultColor += leftColor * convolutionMatrix[1][0] + centerColor * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2];" +
"resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2];" +
"gl_FragColor = resultColor;" +
"}" ;
private float mTexelWidth = 1.0f / 1024f;
private float mTexelHeight = 1.0f / 728;
private float [] mConvolutionMatrix = new float []{
0f, 0f, 0f,
0f, 1f, 0f,
0f, 0f, 0f
};
public GlConvolutionShader() {
super (VERTEX_SHADER, FRAGMENT_SHADER);
}
public float getTexelWidth() {
return mTexelWidth;
}
public void setTexelWidth(final float texelWidth) {
mTexelWidth = texelWidth;
}
public float getTexelHeight() {
return mTexelHeight;
}
public void setTexelHeight(final float texelHeight) {
mTexelHeight = texelHeight;
}
public float [] getConvolutionMatrix() {
return mConvolutionMatrix;
}
public void setConvolutionMatrix(final float [] convolutionMatrix) {
mConvolutionMatrix = convolutionMatrix;
}
//////////////////////////////////////////////////////////////////////////
protected String mShaderName = "Convolution" ;
public String getName() {
return mShaderName;
}
@Override
public void onDraw() {
}
}
Java Source Code List com.af.experiments.FxCameraApp.FilterAdapter.java com.af.experiments.FxCameraApp.MyActivity.java com.af.experiments.FxCameraApp.Utils.BitmapFactoryUtils.java com.af.experiments.FxCameraApp.Utils.ExifUtils.java com.af.experiments.FxCameraApp.Utils.Fps.java com.af.experiments.FxCameraApp.Utils.LogWriter.java com.af.experiments.FxCameraApp.Utils.OpenGlUtils.java com.af.experiments.FxCameraApp.View.CameraView.java com.af.experiments.FxCameraApp.View.DefaultPreview.java com.af.experiments.FxCameraApp.View.GlPreview.java com.af.experiments.FxCameraApp.View.PreviewTexture.java com.af.experiments.FxCameraApp.camera.CameraHelperBase.java com.af.experiments.FxCameraApp.camera.CameraHelperCupcake.java com.af.experiments.FxCameraApp.camera.CameraHelperDonut.java com.af.experiments.FxCameraApp.camera.CameraHelperEclair.java com.af.experiments.FxCameraApp.camera.CameraHelperFactory.java com.af.experiments.FxCameraApp.camera.CameraHelperFroyo.java com.af.experiments.FxCameraApp.camera.CameraHelperGingerbread.java com.af.experiments.FxCameraApp.camera.CameraHelperHonycomb.java com.af.experiments.FxCameraApp.camera.CameraHelperICS.java com.af.experiments.FxCameraApp.camera.CameraHelper.java com.af.experiments.FxCameraApp.display.DisplayHelperBase.java com.af.experiments.FxCameraApp.display.DisplayHelperFactory.java com.af.experiments.FxCameraApp.display.DisplayHelperFroyo.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycombMR2.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycomb.java com.af.experiments.FxCameraApp.display.DisplayHelper.java com.af.experiments.FxCameraApp.ogles.DefaultConfigChooser.java com.af.experiments.FxCameraApp.ogles.DefaultContextFactory.java com.af.experiments.FxCameraApp.ogles.DefaultWindowSurfaceFactory.java com.af.experiments.FxCameraApp.ogles.EGLLogWrapper.java com.af.experiments.FxCameraApp.ogles.GLES20ConfigChooser.java com.af.experiments.FxCameraApp.ogles.GLES20ContextFactory.java com.af.experiments.FxCameraApp.ogles.GlImageBitmapTexture.java com.af.experiments.FxCameraApp.ogles.GlImageResourceTexture.java com.af.experiments.FxCameraApp.ogles.GlImageTexture.java com.af.experiments.FxCameraApp.ogles.GlPreviewTextureFactory.java com.af.experiments.FxCameraApp.ogles.GlSurfaceTexture.java com.af.experiments.FxCameraApp.ogles.GlTextureView.java com.af.experiments.FxCameraApp.ogles.PixelBuffer.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperBase.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperFactory.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelper.java com.af.experiments.FxCameraApp.ogles.Texture.java com.af.experiments.FxCameraApp.renderer.GLES20FramebufferObject.java com.af.experiments.FxCameraApp.renderer.GlFrameBufferObjectRenderer.java com.af.experiments.FxCameraApp.renderer.MainRenderer.java com.af.experiments.FxCameraApp.shaders.GlBilateralShader.java com.af.experiments.FxCameraApp.shaders.GlBoxBlurShader.java com.af.experiments.FxCameraApp.shaders.GlBulgeDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlCGAColorspaceShader.java com.af.experiments.FxCameraApp.shaders.GlColorInvertShader.java com.af.experiments.FxCameraApp.shaders.GlColorMatrixShader.java com.af.experiments.FxCameraApp.shaders.GlColorPackingShader.java com.af.experiments.FxCameraApp.shaders.GlConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlEmbossShader.java com.af.experiments.FxCameraApp.shaders.GlFalseColorShader.java com.af.experiments.FxCameraApp.shaders.GlFastBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGaussianBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGlassSphereShader.java com.af.experiments.FxCameraApp.shaders.GlGrayScaleShader.java com.af.experiments.FxCameraApp.shaders.GlHarrisCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlHazeShader.java com.af.experiments.FxCameraApp.shaders.GlMonochromeShader.java com.af.experiments.FxCameraApp.shaders.GlNobleCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlPerlinNoiseShader.java com.af.experiments.FxCameraApp.shaders.GlPinchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolarPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolkaDotShader.java com.af.experiments.FxCameraApp.shaders.GlPosterizeShader.java com.af.experiments.FxCameraApp.shaders.GlPreviewShader.java com.af.experiments.FxCameraApp.shaders.GlSepiaShader.java com.af.experiments.FxCameraApp.shaders.GlShaderGroup.java com.af.experiments.FxCameraApp.shaders.GlShader.java com.af.experiments.FxCameraApp.shaders.GlSharpenShader.java com.af.experiments.FxCameraApp.shaders.GlShiTomasiFeatureDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSobelEdgeDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSphereRefractionShader.java com.af.experiments.FxCameraApp.shaders.GlStretchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3ConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3TextureSamplingShader.java com.af.experiments.FxCameraApp.shaders.GlToneShader.java com.af.experiments.FxCameraApp.shaders.GlTwoInputShader.java com.af.experiments.FxCameraApp.shaders.GlVignetteShader.java com.af.experiments.FxCameraApp.shaders.GlWeakPixelInclusionShader.java com.af.experiments.FxCameraApp.shaders.GlWhiteBalanceShader.java com.af.experiments.FxCameraApp.shaders.GlXRayShader.java com.af.experiments.FxCameraApp.shaders.GlXYDerivativeShader.java com.af.experiments.FxCameraApp.shaders.fx.GlLutShader.java