Revision 33f59f22
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 |
/// OIT SSBO BUFFER /// |
|
72 |
private static int[] mLinkedListSSBO = new int[1]; |
|
73 |
private static int[] mAtomicCounter = new int[1]; |
|
74 |
|
|
75 |
static |
|
76 |
{ |
|
77 |
mLinkedListSSBO[0]= -1; |
|
78 |
mAtomicCounter[0] = -1; |
|
79 |
} |
|
80 |
|
|
81 |
private static int mBufferSize=(0x1<<23); // 8 million entries |
|
82 |
|
|
71 | 83 |
/// OIT CLEAR PROGRAM /// |
72 | 84 |
private static DistortedProgram mOITClearProgram; |
73 | 85 |
private static int mOITClearDepthH; |
... | ... | |
83 | 95 |
private static int mOITBuildSizeH; |
84 | 96 |
private static int mOITBuildNumRecordsH; |
85 | 97 |
|
86 |
private static int[] mLinkedListSSBO = new int[1]; |
|
87 |
private static int[] mAtomicCounter = new int[1]; |
|
88 |
|
|
89 |
static |
|
90 |
{ |
|
91 |
mLinkedListSSBO[0]= -1; |
|
92 |
mAtomicCounter[0] = -1; |
|
93 |
} |
|
94 |
|
|
95 |
private static int mBufferSize=(0x1<<23); // 8 million entries |
|
98 |
/// OIT COLLAPSE PROGRAM /// |
|
99 |
private static DistortedProgram mOITCollapseProgram; |
|
100 |
private static int mOITCollapseDepthTextureH; |
|
101 |
private static int mOITCollapseDepthH; |
|
102 |
private static int mOITCollapseTexCorrH; |
|
103 |
private static int mOITCollapseSizeH; |
|
96 | 104 |
|
97 | 105 |
/// OIT RENDER PROGRAM /// |
98 | 106 |
private static DistortedProgram mOITRenderProgram; |
99 |
private static int mOITRenderTextureH; |
|
100 |
private static int mOITRenderDepthTextureH; |
|
101 | 107 |
private static int mOITRenderDepthH; |
102 | 108 |
private static int mOITRenderTexCorrH; |
103 | 109 |
private static int mOITRenderSizeH; |
... | ... | |
235 | 241 |
GLES31.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0); |
236 | 242 |
} |
237 | 243 |
|
238 |
// BLIT DEPTH RENDER PROGRAM /////////////////////////// |
|
244 |
// OIT COLLAPSE PROGRAM /////////////////////////// |
|
245 |
final InputStream oitCollapseVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
|
246 |
final InputStream oitCollapseFragStream = resources.openRawResource(R.raw.oit_collapse_fragment_shader); |
|
247 |
|
|
248 |
try |
|
249 |
{ |
|
250 |
mOITCollapseProgram = new DistortedProgram(oitCollapseVertStream,oitCollapseFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL); |
|
251 |
} |
|
252 |
catch(Exception e) |
|
253 |
{ |
|
254 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile OIT COLLAPSE program: "+e.getMessage()); |
|
255 |
throw new RuntimeException(e.getMessage()); |
|
256 |
} |
|
257 |
|
|
258 |
int oitCollapseProgramH = mOITCollapseProgram.getProgramHandle(); |
|
259 |
mOITCollapseDepthTextureH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_DepthTexture"); |
|
260 |
mOITCollapseDepthH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Depth"); |
|
261 |
mOITCollapseTexCorrH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_TexCorr"); |
|
262 |
mOITCollapseSizeH = GLES31.glGetUniformLocation( oitCollapseProgramH, "u_Size"); |
|
263 |
|
|
264 |
// OIT RENDER PROGRAM /////////////////////////// |
|
239 | 265 |
final InputStream oitRenderVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
240 | 266 |
final InputStream oitRenderFragStream = resources.openRawResource(R.raw.oit_render_fragment_shader); |
241 | 267 |
|
... | ... | |
250 | 276 |
} |
251 | 277 |
|
252 | 278 |
int oitRenderProgramH = mOITRenderProgram.getProgramHandle(); |
253 |
mOITRenderTextureH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Texture"); |
|
254 |
mOITRenderDepthTextureH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_DepthTexture"); |
|
255 | 279 |
mOITRenderDepthH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Depth"); |
256 | 280 |
mOITRenderTexCorrH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_TexCorr"); |
257 | 281 |
mOITRenderSizeH = GLES31.glGetUniformLocation( oitRenderProgramH, "u_Size"); |
... | ... | |
470 | 494 |
} |
471 | 495 |
|
472 | 496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
473 |
// Pass3 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists. |
|
497 |
// Pass3 of the OIT algorithm. Cut occluded parts of the linked list. |
|
498 |
|
|
499 |
static void oitCollapse(DistortedOutputSurface surface, float corrW, float corrH) |
|
500 |
{ |
|
501 |
mOITCollapseProgram.useProgram(); |
|
502 |
|
|
503 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
|
504 |
GLES31.glUniform1i(mOITCollapseDepthTextureH, 1); |
|
505 |
GLES31.glUniform2f(mOITCollapseTexCorrH, corrW, corrH ); |
|
506 |
GLES31.glUniform2f(mOITCollapseSizeH, surface.mWidth, surface.mHeight); |
|
507 |
GLES31.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear); |
|
508 |
GLES31.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
509 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
|
510 |
} |
|
511 |
|
|
512 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
513 |
// Pass4 of the OIT algorithm. Render all the transparent pixels from the per-pixel linked lists. |
|
474 | 514 |
|
475 | 515 |
static void oitRender(DistortedOutputSurface surface, float corrW, float corrH) |
476 | 516 |
{ |
477 | 517 |
mOITRenderProgram.useProgram(); |
478 | 518 |
|
479 |
//analyzeBuffer(surface.mWidth, surface.mHeight); |
|
480 |
|
|
481 | 519 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
482 |
GLES31.glUniform1i(mOITRenderTextureH, 0); |
|
483 |
GLES31.glUniform1i(mOITRenderDepthTextureH, 1); |
|
484 | 520 |
GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH ); |
485 | 521 |
GLES31.glUniform2f(mOITRenderSizeH, surface.mWidth, surface.mHeight); |
486 | 522 |
GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear); |
Also available in: Unified diff
OIT: move towards 4 passes ( clear - build - collapse - render )