Revision 7170e4eb
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
94 | 94 |
|
95 | 95 |
private static DistortedProgram mBlur1Program, mBlur2Program; |
96 | 96 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H; |
97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H, mDepthTexture2H;
|
|
97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H; |
|
98 | 98 |
private static float[] mWeights = new float[MAX_BLUR]; |
99 | 99 |
private static float[] mOffsets = new float[MAX_BLUR]; |
100 | 100 |
// another effect .... |
... | ... | |
161 | 161 |
mWeights2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Weights"); |
162 | 162 |
mDepth2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Depth"); |
163 | 163 |
mColorTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_ColorTexture"); |
164 |
mDepthTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_DepthTexture"); |
|
165 | 164 |
} |
166 | 165 |
|
167 | 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
307 | 306 |
DistortedRenderState.unuseStencilMark(); |
308 | 307 |
|
309 | 308 |
// vertical blur |
310 |
GLES30.glViewport(0, 0, (int)w2, (int)h2); |
|
311 | 309 |
mBlur2Program.useProgram(); |
312 | 310 |
buffer2.setAsInput(); |
313 |
buffer2.setAsDepth(); |
|
314 |
surface.setAsOutput(time); |
|
311 |
buffer1.setAsOutput(); |
|
312 |
|
|
313 |
GLES30.glStencilMask(0xff); |
|
314 |
GLES30.glDepthMask(true); |
|
315 |
GLES30.glColorMask(true,true,true,true); |
|
316 |
GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); |
|
317 |
GLES30.glClearDepthf(1.0f); |
|
318 |
GLES30.glClearStencil(0); |
|
319 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
|
315 | 320 |
|
316 | 321 |
GLES30.glUniform1fv( mWeights2H, radius+1, weightsCache,offset); |
317 | 322 |
GLES30.glUniform1i( mRadius2H, radius); |
318 | 323 |
GLES30.glUniform1f( mDepth2H , 1.0f-surface.mNear); |
319 | 324 |
GLES30.glUniform1i( mColorTexture2H , 0 ); |
320 |
GLES30.glUniform1i( mDepthTexture2H , 1 ); |
|
321 | 325 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; |
322 | 326 |
GLES30.glUniform1fv( mOffsets2H ,radius+1, mOffsets,0); |
323 | 327 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
324 | 328 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
329 |
|
|
330 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, buffer2.mDepthStencilH[0], 0); |
|
331 |
DistortedRenderState.useStencilMark(); |
|
325 | 332 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
333 |
DistortedRenderState.unuseStencilMark(); |
|
334 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, buffer1.mDepthStencilH[0], 0); |
|
335 |
|
|
336 |
// blit the results with DEPTH to surface. |
|
337 |
GLES30.glViewport(0, 0, (int)w2, (int)h2); |
|
338 |
buffer1.setAsInput(); |
|
339 |
buffer2.setAsDepth(); |
|
340 |
surface.setAsOutput(time); |
|
341 |
DistortedEffects.blitDepthPriv(surface); |
|
326 | 342 |
|
327 | 343 |
// after each postprocess, clear buffers |
328 | 344 |
GLES30.glStencilMask(0xff); |
... | ... | |
331 | 347 |
GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); |
332 | 348 |
GLES30.glClearDepthf(1.0f); |
333 | 349 |
GLES30.glClearStencil(0); |
334 |
|
|
335 | 350 |
buffer1.setAsOutput(); |
336 | 351 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
337 | 352 |
buffer2.setAsOutput(); |
338 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT); |
|
353 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
|
|
339 | 354 |
} |
340 | 355 |
|
341 | 356 |
return mNumEffects; |
Also available in: Unified diff
Move on to Stencil on both stages of the BLUR + separate 'blit with depth'.
This works wonders on Nexus 5X ( r=50 quality=HIGHIEST 1,4,8 cubes: 59.3,43.6,41.0 FPS! ) but it somehow fails to clear the DEPTH and STENCIL buffers on Nexus 4....