Project

General

Profile

« Previous | Next » 

Revision 33f59f22

Added by Leszek Koltunski almost 6 years ago

OIT: move towards 4 passes ( clear - build - collapse - render )

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
71 71

  
72 72
  // Global buffers used for postprocessing.
73 73
  private static DistortedOutputSurface[] mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH];
74
  private static DistortedOutputSurface   mBufferOIT;
75 74

  
76 75
  private long mTime;
77 76
  private float mFOV;
......
211 210
      {
212 211
      mBuffer[j] = null;
213 212
      }
214

  
215
    mBufferOIT = null;
216 213
    }
217 214

  
218 215
///////////////////////////////////////////////////////////////////////////////////////////////////
......
259 256

  
260 257
  private static void oitClear(DistortedOutputSurface buffer)
261 258
    {
262
    if( mBufferOIT==null )
263
      {
264
      mBufferOIT = new DistortedFramebuffer(1, BOTH_DEPTH_STENCIL, TYPE_SYST, buffer.mWidth, buffer.mHeight);
265
      mBufferOIT.mMipmap = 1.0f;
266
      mBufferOIT.mNear = buffer.mNear;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
267
      mBufferOIT.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
268

  
269
      DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
270
      }
271

  
272
    if( mBufferOIT.mWidth != buffer.mWidth || mBufferOIT.mHeight != buffer.mHeight )
273
      {
274
      mBufferOIT.mWidth  = (int)(buffer.mWidth *mBufferOIT.mMipmap);
275
      mBufferOIT.mHeight = (int)(buffer.mHeight*mBufferOIT.mMipmap);
276

  
277
      mBufferOIT.mNear   = buffer.mNear;  // Near plane is independent of the mipmap level
278

  
279
      //android.util.Log.e("surface", "viewport "+i+" to ("+from.mWidth+"x"+from.mHeight+")");
280

  
281
      mBufferOIT.createProjection();
282

  
283
      int maxw = mBufferOIT.mWidth  > mBufferOIT.mRealWidth  ? mBufferOIT.mWidth  : mBufferOIT.mRealWidth;
284
      int maxh = mBufferOIT.mHeight > mBufferOIT.mRealHeight ? mBufferOIT.mHeight : mBufferOIT.mRealHeight;
285

  
286
      if (maxw > mBufferOIT.mRealWidth || maxh > mBufferOIT.mRealHeight)
287
        {
288
        mBufferOIT.mRealWidth = maxw;
289
        mBufferOIT.mRealHeight = maxh;
290

  
291
        mBufferOIT.recreate();
292
        mBufferOIT.create();
293
        }
294
      }
295

  
296
    if( mBufferOIT.mNear != buffer.mNear || mBufferOIT.mFOV != buffer.mFOV )
297
      {
298
      mBufferOIT.mNear = buffer.mNear;
299
      mBufferOIT.mFOV  = buffer.mFOV;
300
      mBufferOIT.createProjection();
301
      }
302

  
303
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBufferOIT.mFBOH[0]);
304
    DistortedRenderState.colorDepthStencilOn();
305
    GLES31.glClearColor(buffer.mClearR, buffer.mClearG, buffer.mClearB, buffer.mClearA);
306
    GLES31.glClearDepthf(buffer.mClearDepth);
307
    GLES31.glClearStencil(buffer.mClearStencil);
308
    GLES31.glClear(buffer.mClear);
309
    DistortedRenderState.colorDepthStencilRestore();
310

  
311 259
    DistortedEffects.zeroOutAtomic();
312 260
    DistortedEffects.oitClear(buffer);
313

  
314 261
    GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
315 262
    }
316 263

  
......
344 291
    }
345 292

  
346 293
///////////////////////////////////////////////////////////////////////////////////////////////////
294
// two phases: 1. collapse the SSBO 2. blend the ssbo's color
347 295

  
348 296
  private int oitRender(long currTime, DistortedOutputSurface buffer)
349 297
    {
350
    if( buffer==this )
351
      {
352
      android.util.Log.e("surface", "feedback loop in oitRender!");
353
      return 0;
354
      }
298
    float corrW = buffer.getWidthCorrection();
299
    float corrH = buffer.getHeightCorrection();
355 300

  
356 301
    GLES31.glViewport(0, 0, mWidth, mHeight);
357 302
    setAsOutput(currTime);
358
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
359
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[0]);
360 303
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
361 304
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[0]);
362 305

  
363
    DistortedRenderState.disableStencil();
364
    DistortedEffects.oitRender(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() );
365
    DistortedRenderState.restoreStencil();
306
    DistortedRenderState.switchOffColorDepthStencil();
307
    DistortedEffects.oitCollapse(this, corrW, corrH );
366 308

  
367 309
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
368 310
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
369 311

  
312
    DistortedRenderState.switchColorDepthOnStencilOff();
313
    DistortedEffects.oitRender(this, corrW, corrH);
314
    DistortedRenderState.restoreColorDepthStencil();
315

  
370 316
    return 1;
371 317
    }
372 318

  
......
414 360
    int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0;
415 361
    DistortedNode child1, child2;
416 362
    EffectQueuePostprocess lastQueue=null, currQueue;
417
    long lastBucket=0, currBucket=0;
363
    long lastBucket=0, currBucket;
418 364

  
419 365
    oitClear(this);
420 366

  
......
426 372

  
427 373
      if( currBucket==0 )
428 374
        {
429
        GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBufferOIT.mFBOH[0]);
430
        numRenders += child1.draw(time, mBufferOIT);
375
        GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
376
        numRenders += child1.draw(time, this);
431 377

  
432 378
        //setAsOutput(time);
433 379
        //numRenders += child1.draw(time,this);
......
451 397
              }
452 398

  
453 399
            numRenders += lastQueue.postprocess(mBuffer);
454
            numRenders += mBufferOIT.oitBuild(mBuffer[quality]);
400
            numRenders += oitBuild(mBuffer[quality]);
455 401
            clearBuffer(mBuffer[quality]);
456 402
            }
457 403

  
......
472 418
            }
473 419

  
474 420
          numRenders += currQueue.postprocess(mBuffer);
475
          numRenders += mBufferOIT.oitBuild(mBuffer[quality]);
421
          numRenders += oitBuild(mBuffer[quality]);
476 422
          GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT);
477
          numRenders += oitRender(time,mBufferOIT);  // merge the OIT linked list
423
          numRenders += oitRender(time,this);  // merge the OIT linked list
478 424
          clearBuffer(mBuffer[quality]);
479 425
          }
480 426
        } // end else (postprocessed child)
......
483 429
      lastBucket= currBucket;
484 430
      } // end main for loop
485 431

  
486
    if( currBucket==0 ) // there was no postprocessing - we need to merge the main buffer
487
      {
488
      numRenders += oitRender(time,mBufferOIT);
489
      }
490

  
491 432
    return numRenders;
492 433
    }
493 434

  

Also available in: Unified diff