Revision 56c6ca24
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
68 | 68 |
mQuadPositions.put(positionData).position(0); |
69 | 69 |
} |
70 | 70 |
|
71 |
/// BLIT DEPTH PROGRAM /// |
|
72 |
private static DistortedProgram mBlitDepthProgram; |
|
73 |
private static int mBlitDepthTextureH; |
|
74 |
private static int mBlitDepthDepthTextureH; |
|
75 |
private static int mBlitDepthDepthH; |
|
76 |
private static int mBlitDepthTexCorrH; |
|
77 |
private static int mBlitDepthSizeH; |
|
78 |
private static int mBlitDepthNumRecordsH; |
|
71 |
/// OIT CLEAR PROGRAM /// |
|
72 |
private static DistortedProgram mOITClearProgram; |
|
73 |
private static int mOITClearDepthH; |
|
74 |
private static int mOITClearTexCorrH; |
|
75 |
private static int mOITClearSizeH; |
|
76 |
|
|
77 |
/// OIT BUILD PROGRAM /// |
|
78 |
private static DistortedProgram mOITBuildProgram; |
|
79 |
private static int mOITBuildTextureH; |
|
80 |
private static int mOITBuildDepthTextureH; |
|
81 |
private static int mOITBuildDepthH; |
|
82 |
private static int mOITBuildTexCorrH; |
|
83 |
private static int mOITBuildSizeH; |
|
84 |
private static int mOITBuildNumRecordsH; |
|
79 | 85 |
|
80 | 86 |
private static int[] mLinkedListSSBO = new int[1]; |
81 | 87 |
private static int[] mAtomicCounter = new int[1]; |
... | ... | |
88 | 94 |
|
89 | 95 |
private static int mBufferSize=(0x1<<23); // 8 million entries |
90 | 96 |
|
91 |
/// BLIT DEPTH RENDER PROGRAM /// |
|
92 |
private static DistortedProgram mBlitDepthRenderProgram; |
|
93 |
private static int mBlitDepthRenderDepthTextureH; |
|
94 |
private static int mBlitDepthRenderDepthH; |
|
95 |
private static int mBlitDepthRenderTexCorrH; |
|
96 |
private static int mBlitDepthRenderSizeH; |
|
97 |
/// OIT RENDER PROGRAM /// |
|
98 |
private static DistortedProgram mOITRenderProgram; |
|
99 |
private static int mOITRenderTextureH; |
|
100 |
private static int mOITRenderDepthTextureH; |
|
101 |
private static int mOITRenderDepthH; |
|
102 |
private static int mOITRenderTexCorrH; |
|
103 |
private static int mOITRenderSizeH; |
|
97 | 104 |
|
98 | 105 |
/// NORMAL PROGRAM ///// |
99 | 106 |
private static DistortedProgram mNormalProgram; |
... | ... | |
155 | 162 |
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader); |
156 | 163 |
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader); |
157 | 164 |
|
158 |
String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n" ); |
|
159 |
String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n"); |
|
160 |
|
|
161 | 165 |
try |
162 | 166 |
{ |
163 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
|
|
167 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
|
164 | 168 |
} |
165 | 169 |
catch(Exception e) |
166 | 170 |
{ |
... | ... | |
172 | 176 |
mBlitTextureH = GLES31.glGetUniformLocation( blitProgramH, "u_Texture"); |
173 | 177 |
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth"); |
174 | 178 |
|
175 |
// BLIT DEPTH PROGRAM ////////////////////////////////////
|
|
176 |
final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
|
|
177 |
final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader);
|
|
179 |
// OIT CLEAR PROGRAM ////////////////////////////////////
|
|
180 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
|
181 |
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader);
|
|
178 | 182 |
|
179 | 183 |
try |
180 | 184 |
{ |
181 |
mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
|
|
185 |
mOITClearProgram = new DistortedProgram(oitClearVertStream,oitClearFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
|
182 | 186 |
} |
183 | 187 |
catch(Exception e) |
184 | 188 |
{ |
185 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
|
|
189 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT CLEAR program: "+e.getMessage());
|
|
186 | 190 |
throw new RuntimeException(e.getMessage()); |
187 | 191 |
} |
188 | 192 |
|
189 |
int blitDepthProgramH = mBlitDepthProgram.getProgramHandle(); |
|
190 |
mBlitDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture"); |
|
191 |
mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture"); |
|
192 |
mBlitDepthDepthH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth"); |
|
193 |
mBlitDepthTexCorrH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr"); |
|
194 |
mBlitDepthSizeH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Size"); |
|
195 |
mBlitDepthNumRecordsH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_numRecords"); |
|
193 |
int oitClearProgramH = mOITClearProgram.getProgramHandle(); |
|
194 |
mOITClearDepthH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Depth"); |
|
195 |
mOITClearTexCorrH = GLES31.glGetUniformLocation( oitClearProgramH, "u_TexCorr"); |
|
196 |
mOITClearSizeH = GLES31.glGetUniformLocation( oitClearProgramH, "u_Size"); |
|
197 |
|
|
198 |
// OIT BUILD PROGRAM //////////////////////////////////// |
|
199 |
final InputStream oitBuildVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
|
200 |
final InputStream oitBuildFragStream = resources.openRawResource(R.raw.oit_build_fragment_shader); |
|
201 |
|
|
202 |
try |
|
203 |
{ |
|
204 |
mOITBuildProgram = new DistortedProgram(oitBuildVertStream,oitBuildFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL); |
|
205 |
} |
|
206 |
catch(Exception e) |
|
207 |
{ |
|
208 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT BUILD program: "+e.getMessage()); |
|
209 |
throw new RuntimeException(e.getMessage()); |
|
210 |
} |
|
211 |
|
|
212 |
int oitBuildProgramH = mOITBuildProgram.getProgramHandle(); |
|
213 |
mOITBuildTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Texture"); |
|
214 |
mOITBuildDepthTextureH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_DepthTexture"); |
|
215 |
mOITBuildDepthH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Depth"); |
|
216 |
mOITBuildTexCorrH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_TexCorr"); |
|
217 |
mOITBuildSizeH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_Size"); |
|
218 |
mOITBuildNumRecordsH = GLES31.glGetUniformLocation( oitBuildProgramH, "u_numRecords"); |
|
196 | 219 |
|
197 | 220 |
if( mLinkedListSSBO[0]<0 ) |
198 | 221 |
{ |
... | ... | |
213 | 236 |
} |
214 | 237 |
|
215 | 238 |
// BLIT DEPTH RENDER PROGRAM /////////////////////////// |
216 |
final InputStream blitDepthRenderVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
|
|
217 |
final InputStream blitDepthRenderFragStream = resources.openRawResource(R.raw.blit_depth_render_fragment_shader);
|
|
239 |
final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader);
|
|
240 |
final InputStream oitRenderFragStream = resources.openRawResource(R.raw.oit_render_fragment_shader);
|
|
218 | 241 |
|
219 | 242 |
try |
220 | 243 |
{ |
221 |
mBlitDepthRenderProgram = new DistortedProgram(blitDepthRenderVertStream,blitDepthRenderFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
|
|
244 |
mOITRenderProgram = new DistortedProgram(oitRenderVertStream,oitRenderFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL);
|
|
222 | 245 |
} |
223 | 246 |
catch(Exception e) |
224 | 247 |
{ |
225 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH RENDER program: "+e.getMessage());
|
|
248 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT RENDER program: "+e.getMessage());
|
|
226 | 249 |
throw new RuntimeException(e.getMessage()); |
227 | 250 |
} |
228 | 251 |
|
229 |
int blitDepthRenderProgramH = mBlitDepthRenderProgram.getProgramHandle(); |
|
230 |
mBlitDepthRenderDepthTextureH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_DepthTexture"); |
|
231 |
mBlitDepthRenderDepthH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_Depth"); |
|
232 |
mBlitDepthRenderTexCorrH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_TexCorr"); |
|
233 |
mBlitDepthRenderSizeH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_Size"); |
|
252 |
int oitRenderProgramH = mOITRenderProgram.getProgramHandle(); |
|
253 |
mOITRenderTextureH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Texture"); |
|
254 |
mOITRenderDepthTextureH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_DepthTexture"); |
|
255 |
mOITRenderDepthH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Depth"); |
|
256 |
mOITRenderTexCorrH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_TexCorr"); |
|
257 |
mOITRenderSizeH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Size"); |
|
234 | 258 |
|
235 | 259 |
// NORMAL PROGRAM ////////////////////////////////////// |
236 | 260 |
final InputStream normalVertexStream = resources.openRawResource(R.raw.normal_vertex_shader); |
... | ... | |
393 | 417 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[0] ); |
394 | 418 |
|
395 | 419 |
ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4, |
396 |
GLES31.GL_MAP_READ_BIT|GLES31.GL_MAP_WRITE_BIT);
|
|
420 |
GLES31.GL_MAP_WRITE_BIT|GLES31.GL_MAP_INVALIDATE_BUFFER_BIT);
|
|
397 | 421 |
if( atomicBuf!=null ) |
398 | 422 |
{ |
399 | 423 |
IntBuffer atomicIntBuf = atomicBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
... | ... | |
413 | 437 |
} |
414 | 438 |
|
415 | 439 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
440 |
// Pass1 of the OIT algorithm. Clear per-pixel head-poiners. |
|
441 |
|
|
442 |
static void oitClear(DistortedOutputSurface surface) |
|
443 |
{ |
|
444 |
mOITClearProgram.useProgram(); |
|
445 |
|
|
446 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
|
447 |
GLES31.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f ); // corrections do not really matter here - only present because of common vertex shader. |
|
448 |
GLES31.glUniform1f( mOITClearDepthH , 1.0f); // likewise depth |
|
449 |
GLES31.glUniform2f(mOITClearSizeH, surface.mWidth, surface.mHeight); |
|
450 |
GLES31.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
451 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
|
452 |
} |
|
453 |
|
|
454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
455 |
// Pass2 of the OIT algorithm - build per-pixel linked lists. |
|
416 | 456 |
|
417 |
static void blitDepth(DistortedOutputSurface surface, float corrW, float corrH)
|
|
457 |
static void oitBuild(DistortedOutputSurface surface, float corrW, float corrH)
|
|
418 | 458 |
{ |
419 |
mBlitDepthProgram.useProgram();
|
|
459 |
mOITBuildProgram.useProgram();
|
|
420 | 460 |
|
421 | 461 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
422 |
GLES31.glUniform1i(mBlitDepthTextureH, 0);
|
|
423 |
GLES31.glUniform1i(mBlitDepthDepthTextureH, 1);
|
|
424 |
GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
|
|
425 |
GLES31.glUniform2f(mBlitDepthSizeH, surface.mWidth, surface.mHeight);
|
|
426 |
GLES31.glUniform1ui(mBlitDepthNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader
|
|
427 |
GLES31.glUniform1f(mBlitDepthDepthH , 1.0f-surface.mNear);
|
|
428 |
GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
462 |
GLES31.glUniform1i(mOITBuildTextureH, 0);
|
|
463 |
GLES31.glUniform1i(mOITBuildDepthTextureH, 1);
|
|
464 |
GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
|
|
465 |
GLES31.glUniform2f(mOITBuildSizeH, surface.mWidth, surface.mHeight);
|
|
466 |
GLES31.glUniform1ui(mOITBuildNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader
|
|
467 |
GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
|
|
468 |
GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
|
|
429 | 469 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
430 | 470 |
} |
431 | 471 |
|
432 | 472 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
433 |
// render all the transparent pixels from the per-pixel linked lists. This is in the 'merge |
|
434 |
// postprocessing buckets' stage. |
|
473 |
// Pass3 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists. |
|
435 | 474 |
|
436 |
static void mergeOIT(DistortedOutputSurface surface, float corrW, float corrH)
|
|
475 |
static void oitRender(DistortedOutputSurface surface, float corrW, float corrH)
|
|
437 | 476 |
{ |
438 |
mBlitDepthRenderProgram.useProgram();
|
|
477 |
mOITRenderProgram.useProgram();
|
|
439 | 478 |
|
440 | 479 |
//analyzeBuffer(surface.mWidth, surface.mHeight); |
441 | 480 |
|
442 | 481 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
443 |
GLES31.glUniform1i(mBlitDepthRenderDepthTextureH, 1); |
|
444 |
GLES31.glUniform2f(mBlitDepthRenderTexCorrH, corrW, corrH ); |
|
445 |
GLES31.glUniform2f(mBlitDepthRenderSizeH, surface.mWidth, surface.mHeight); |
|
446 |
GLES31.glUniform1f( mBlitDepthRenderDepthH , 1.0f-surface.mNear); |
|
447 |
GLES31.glVertexAttribPointer(mBlitDepthRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
482 |
GLES31.glUniform1i(mOITRenderTextureH, 0); |
|
483 |
GLES31.glUniform1i(mOITRenderDepthTextureH, 1); |
|
484 |
GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH ); |
|
485 |
GLES31.glUniform2f(mOITRenderSizeH, surface.mWidth, surface.mHeight); |
|
486 |
GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear); |
|
487 |
GLES31.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
448 | 488 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
449 | 489 |
} |
450 | 490 |
|
Also available in: Unified diff
OIT: lots of progress on all fronts. Still a few bugs to solve though!