Revision 95c441a2
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
137 | 137 |
|
138 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 | 139 |
|
140 |
synchronized void compute(long currTime)
|
|
140 |
synchronized boolean compute(long currTime)
|
|
141 | 141 |
{ |
142 |
if( currTime==mTime ) return; |
|
142 |
if( currTime==mTime ) return false;
|
|
143 | 143 |
if( mTime==0 ) mTime = currTime; |
144 | 144 |
long step = (currTime-mTime); |
145 | 145 |
|
... | ... | |
166 | 166 |
} |
167 | 167 |
} |
168 | 168 |
|
169 |
mTime = currTime; |
|
169 |
mTime = currTime; |
|
170 |
|
|
171 |
return true; |
|
170 | 172 |
} |
171 | 173 |
|
172 | 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
227 | 229 |
} |
228 | 230 |
|
229 | 231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 |
// w,h - width and height of the input texture. MVP - Model-View-Projection matrix to apply to the |
|
231 |
// texture; df - output FBO. |
|
232 | 232 |
|
233 |
synchronized void render(float w, float h, float[] mvp, DistortedOutputSurface surface)
|
|
233 |
int postprocess(long time, DistortedOutputSurface surface)
|
|
234 | 234 |
{ |
235 |
mBlurProgram.useProgram(); |
|
236 |
|
|
237 |
int radius = (int)mUniforms[0]; |
|
238 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
|
239 |
computeGaussianKernel(radius); |
|
235 |
if( mNumEffects>0 && compute(time) ) |
|
236 |
{ |
|
237 |
mMainBuffer.setAsInput(); |
|
238 |
|
|
239 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
240 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -surface.mDistance); |
|
241 |
Matrix.multiplyMM(mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
242 |
|
|
243 |
float w = surface.mWidth; |
|
244 |
float h = surface.mHeight; |
|
245 |
|
|
246 |
mBlurProgram.useProgram(); |
|
247 |
|
|
248 |
int radius = (int)mUniforms[0]; |
|
249 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
|
250 |
computeGaussianKernel(radius); |
|
251 |
|
|
252 |
int offset = radius + radius*radius/4; |
|
253 |
radius = (radius+1)/2; |
|
254 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
255 |
|
|
256 |
GLES30.glUniform1fv( mWeightsH, radius+1, weightsCache,offset); |
|
257 |
GLES30.glUniform1i( mRadiusH, radius); |
|
258 |
GLES30.glUniform2f( mObjDH , w, h ); |
|
259 |
|
|
260 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
261 |
mPostBuffer.setAsOutput(time); |
|
262 |
GLES30.glViewport(0, 0, (int)w, (int)h); |
|
263 |
|
|
264 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
265 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -mPostBuffer.mDistance); |
|
266 |
Matrix.multiplyMM(mMVPMatrix, 0, mPostBuffer.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
267 |
|
|
268 |
// horizontal blur |
|
269 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
270 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
|
271 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
272 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
273 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
274 |
|
|
275 |
// vertical blur |
|
276 |
mPostBuffer.setAsInput(); |
|
277 |
surface.setAsOutput(time); |
|
278 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
|
279 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
280 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
281 |
} |
|
240 | 282 |
|
241 |
int offset = radius + radius*radius/4; |
|
242 |
radius = (radius+1)/2; |
|
243 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
244 |
|
|
245 |
GLES30.glUniform1fv( mWeightsH, radius+1, weightsCache,offset); |
|
246 |
GLES30.glUniform1i( mRadiusH, radius); |
|
247 |
GLES30.glUniform2f( mObjDH , w, h ); |
|
248 |
|
|
249 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
250 |
mPostBuffer.setAsOutput(); |
|
251 |
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
|
252 |
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT); |
|
253 |
GLES30.glViewport(0, 0, (int)w, (int)h); |
|
254 |
|
|
255 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
256 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -mPostBuffer.mDistance); |
|
257 |
Matrix.multiplyMM(mMVPMatrix, 0, mPostBuffer.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
258 |
|
|
259 |
// horizontal blur |
|
260 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
261 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
|
262 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
263 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
264 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
265 |
|
|
266 |
mPostBuffer.setAsInput(); |
|
267 |
surface.setAsOutput(); |
|
268 |
|
|
269 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight); |
|
270 |
|
|
271 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
|
272 |
|
|
273 |
// vertical blur |
|
274 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
275 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0); |
|
276 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
277 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
278 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
283 |
return mNumEffects; |
|
279 | 284 |
} |
280 | 285 |
|
281 | 286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with Multiblur.
This introduces some regressions with transparency (see: 'Different Bitmaps' and 'Around the world' )