77 |
77 |
|
78 |
78 |
// BLUR effect
|
79 |
79 |
private static DistortedProgram mBlurProgram;
|
80 |
|
private static int mRadiusH,mStepH,mWeightsH,mObjDH,mMVPMatrixH;
|
|
80 |
private static int mRadiusH,mOffsetsH,mWeightsH,mObjDH,mMVPMatrixH;
|
81 |
81 |
private float[] mWeights = new float[MAX_BLUR];
|
82 |
|
|
|
82 |
private float[] mOffsets = new float[MAX_BLUR];
|
83 |
83 |
// another effect ....
|
84 |
84 |
|
85 |
85 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
103 |
103 |
|
104 |
104 |
int blurProgramH = mBlurProgram.getProgramHandle();
|
105 |
105 |
mRadiusH = GLES30.glGetUniformLocation( blurProgramH, "u_Radius");
|
106 |
|
mStepH = GLES30.glGetUniformLocation( blurProgramH, "u_Step");
|
|
106 |
mOffsetsH = GLES30.glGetUniformLocation( blurProgramH, "u_Offsets");
|
107 |
107 |
mWeightsH = GLES30.glGetUniformLocation( blurProgramH, "u_Weights");
|
108 |
108 |
mObjDH = GLES30.glGetUniformLocation( blurProgramH, "u_objD");
|
109 |
109 |
mMVPMatrixH = GLES30.glGetUniformLocation( blurProgramH, "u_MVPMatrix");
|
... | ... | |
167 |
167 |
for(int i=0; i<=radius; i++)
|
168 |
168 |
{
|
169 |
169 |
mWeights[i] = 1.0f / (2.0f*radius+1.0f);
|
|
170 |
mOffsets[i] = i/h;
|
170 |
171 |
}
|
171 |
172 |
|
172 |
173 |
GLES30.glUniform1fv( mWeightsH, radius+1, mWeights,0);
|
|
174 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
|
173 |
175 |
GLES30.glUniform1i( mRadiusH, radius);
|
174 |
176 |
GLES30.glUniform2f( mObjDH , w, h );
|
175 |
177 |
|
... | ... | |
182 |
184 |
Matrix.multiplyMM(mMVPMatrix, 0, mBufferFBO.mProjectionMatrix, 0, mTmpMatrix, 0);
|
183 |
185 |
|
184 |
186 |
// horizontal blur
|
185 |
|
GLES30.glUniform1f( mStepH , 1/h );
|
|
187 |
|
186 |
188 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
187 |
189 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
188 |
190 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
|
... | ... | |
192 |
194 |
df.setAsOutput();
|
193 |
195 |
GLES30.glViewport(0, 0, df.mWidth, df.mHeight);
|
194 |
196 |
|
|
197 |
float adjust = h/w;
|
|
198 |
for(int i=0; i<=radius; i++) mOffsets[i] *= adjust;
|
|
199 |
|
195 |
200 |
// vertical blur
|
196 |
|
GLES30.glUniform1f( mStepH , 1/w );
|
|
201 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
|
197 |
202 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
|
198 |
203 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
|
199 |
204 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE , GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
|
Separable Box blur fully works now!