parent
9d0cb83334
commit
e112ecdeb9
@ -0,0 +1,33 @@ |
|||||||
|
package com.frank.camerafilter.filter.advance; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.opengl.GLES30; |
||||||
|
|
||||||
|
import com.frank.camerafilter.R; |
||||||
|
import com.frank.camerafilter.filter.BaseFilter; |
||||||
|
import com.frank.camerafilter.util.OpenGLUtil; |
||||||
|
|
||||||
|
public class BeautyBlurFilter extends BaseFilter { |
||||||
|
|
||||||
|
private int blurSize; |
||||||
|
|
||||||
|
public BeautyBlurFilter(Context context) { |
||||||
|
super(NORMAL_VERTEX_SHADER, OpenGLUtil.readShaderFromSource(context, R.raw.zoomblur)); |
||||||
|
} |
||||||
|
|
||||||
|
protected void onInit() { |
||||||
|
super.onInit(); |
||||||
|
blurSize = GLES30.glGetUniformLocation(getProgramId(), "blurSize"); |
||||||
|
} |
||||||
|
|
||||||
|
protected void onInitialized() { |
||||||
|
super.onInitialized(); |
||||||
|
setFloat(blurSize, 0.3f); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onInputSizeChanged(int width, int height) { |
||||||
|
super.onInputSizeChanged(width, height); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
varying highp vec2 textureCoordinate; |
||||||
|
|
||||||
|
uniform sampler2D inputImageTexture; |
||||||
|
|
||||||
|
uniform highp vec2 blurCenter; |
||||||
|
uniform highp float blurSize; |
||||||
|
|
||||||
|
void main() |
||||||
|
{ |
||||||
|
// TODO: Do a more intelligent scaling based on resolution here |
||||||
|
highp vec2 samplingOffset = 1.0/100.0 * (blurCenter - textureCoordinate) * blurSize; |
||||||
|
|
||||||
|
lowp vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate + samplingOffset) * 0.15; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (2.0 * samplingOffset)) * 0.12; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (3.0 * samplingOffset)) * 0.09; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (4.0 * samplingOffset)) * 0.05; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate - samplingOffset) * 0.15; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (2.0 * samplingOffset)) * 0.12; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (3.0 * samplingOffset)) * 0.09; |
||||||
|
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (4.0 * samplingOffset)) * 0.05; |
||||||
|
|
||||||
|
gl_FragColor = fragmentColor; |
||||||
|
} |
Loading…
Reference in new issue